class RestClient::Resource
@api private
Public Instance Methods
Creates a Conjur
API from this resource’s authorization header.
The new API is created using the token, so it will not be able to refresh when the token expires (after about 8 minutes). This is equivalent to creating an {Conjur::API} instance with {Conjur::API.new_from_token}.
@return {Conjur::API} the new api
# File lib/conjur/api.rb, line 73 def conjur_api api = Conjur::API.new_from_token token, remote_ip: remote_ip api end
# File lib/conjur/api.rb, line 95 def remote_ip options[:headers][:x_forwarded_for] end
@api private This method exists so that all {RestClient::Resource}s support JSON serialization. It returns an empty hash. @return [Hash] the empty hash
# File lib/conjur/api.rb, line 62 def to_json(options = {}) {} end
Get an authentication token from the clients Authorization header.
Useful fields in the token include ‘“data”`, which holds the username for which the token was issued, and `“timestamp”`, which contains the time at which the token was issued. The token will expire 8 minutes after timestamp, but we recommend you treat the lifespan as about 5 minutes to account for time differences.
@return [Hash] the parsed authentication token
# File lib/conjur/api.rb, line 86 def token authorization = options[:headers][:authorization] if authorization && authorization.to_s[/^Token token="(.*)"/] JSON.parse(Base64.decode64($1)) else raise AuthorizationError.new("Authorization missing") end end
The username this resource authenticates as.
@return [String] the username
# File lib/conjur/api.rb, line 102 def username options[:user] || options[:username] end