class ADAL::AuthenticationParameters
Authentication parameters from an unauthorized 401 response from a resource server that can be used to create an AuthenticationContext
.
Constants
- AUTHENTICATE_HEADER
- AUTHORITY_KEY
- BEARER_CHALLENGE_VALIDATION
- FIRST_KEY_VALUE
- OTHER_KEY_VALUE
- RESOURCE_KEY
Attributes
Public Class Methods
Creates an AuthenticationParameters
object from a www-authenticate response header.
@param String challenge
The raw www-authenticate header.
@return AuthenticationParameters
# File lib/adal/authentication_parameters.rb, line 77 def self.create_from_authenticate_header(challenge) params = parse_challenge(challenge) if params.nil? || !params.key?(AUTHORITY_KEY) logger.warn('Unable to create AuthenticationParameters from header ' \ "#{challenge}.") return end logger.verbose("Authentication header #{challenge} was successfully " \ 'parsed as an OAuth challenge into a parameters hash.') AuthenticationParameters.new( params[AUTHORITY_KEY], params[RESOURCE_KEY]) end
Creates authentication parameters from the address of the resource. The resource server must respond with 401 unauthorized response with a www-authenticate header containing the authentication parameters.
@param URI resource_url
The address of the desired resource.
@return AuthenticationParameters
# File lib/adal/authentication_parameters.rb, line 59 def self.create_from_resource_url(resource_url) logger.verbose('Attempting to retrieve authentication parameters from ' \ "#{resource_url}.") response = Net::HTTP.post_form(URI.parse(resource_url.to_s), {}) unless response.key? AUTHENTICATE_HEADER fail ArgumentError, 'The specified resource uri does not support ' \ 'OAuth challenges.' end create_from_authenticate_header(response[AUTHENTICATE_HEADER]) end
Constructs a new AuthenticationParameters
.
@param String|URI authority_uri
The uri of the authority server, including both host and tenant.
@param String
# File lib/adal/authentication_parameters.rb, line 112 def initialize(authority_uri, resource = nil) fail_if_arguments_nil(authority_uri) @authority_uri = URI.parse(authority_uri.to_s) @resource = resource end
Private Class Methods
Parses a challenge from the www-authenticate header into a hash of parameters.
@param String challenge @return Hash
# File lib/adal/authentication_parameters.rb, line 96 def self.parse_challenge(challenge) if challenge !~ BEARER_CHALLENGE_VALIDATION logger.warn("#{challenge} is not parseable as an RFC6750 OAuth2 " \ 'challenge.') return end Hash[challenge.scan(FIRST_KEY_VALUE) + challenge.scan(OTHER_KEY_VALUE)] end
Public Instance Methods
Creates an AuthenticationContext
based on the parameters.
@return AuthenticationContext
# File lib/adal/authentication_parameters.rb, line 122 def create_context AuthenticationContext.new(@authority_uri.host, @authority_uri.path[1..-1]) end