Class: ADAL::AuthenticationParameters
- Inherits:
-
Object
- Object
- ADAL::AuthenticationParameters
- Extended by:
- Logging
- Includes:
- Util
- Defined in:
- lib/adal/authentication_parameters.rb
Overview
Authentication parameters from an unauthorized 401 response from a resource server that can be used to create an AuthenticationContext.
Constant Summary collapse
- AUTHENTICATE_HEADER =
'www-authenticate'
- AUTHORITY_KEY =
'authorization_uri'
- RESOURCE_KEY =
'resource'
Constants included from Logging
Logging::DEFAULT_LOG_LEVEL, Logging::DEFAULT_LOG_OUTPUT
Instance Attribute Summary collapse
-
#authority_uri ⇒ Object
readonly
Returns the value of attribute authority_uri.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Class Method Summary collapse
-
.create_from_authenticate_header(challenge) ⇒ Object
Creates an AuthenticationParameters object from a www-authenticate response header.
-
.create_from_resource_url(resource_url) ⇒ Object
Creates authentication parameters from the address of the resource.
Instance Method Summary collapse
-
#create_context ⇒ Object
Creates an AuthenticationContext based on the parameters.
-
#initialize(authority_uri, resource = nil) ⇒ AuthenticationParameters
constructor
Constructs a new AuthenticationParameters.
Methods included from Logging
Methods included from Util
#fail_if_arguments_nil, #http, #string_hash
Constructor Details
#initialize(authority_uri, resource = nil) ⇒ AuthenticationParameters
Constructs a new AuthenticationParameters.
112 113 114 115 116 |
# File 'lib/adal/authentication_parameters.rb', line 112 def initialize(, resource = nil) fail_if_arguments_nil() @authority_uri = URI.parse(.to_s) @resource = resource end |
Instance Attribute Details
#authority_uri ⇒ Object (readonly)
Returns the value of attribute authority_uri.
48 49 50 |
# File 'lib/adal/authentication_parameters.rb', line 48 def @authority_uri end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
49 50 51 |
# File 'lib/adal/authentication_parameters.rb', line 49 def resource @resource end |
Class Method Details
.create_from_authenticate_header(challenge) ⇒ Object
Creates an AuthenticationParameters object from a www-authenticate response header.
77 78 79 80 81 82 83 84 85 86 87 88 |
# 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 |
.create_from_resource_url(resource_url) ⇒ Object
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.
59 60 61 62 63 64 65 66 67 68 |
# 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 |
Instance Method Details
#create_context ⇒ Object
Creates an AuthenticationContext based on the parameters.
122 123 124 |
# File 'lib/adal/authentication_parameters.rb', line 122 def create_context AuthenticationContext.new(@authority_uri.host, @authority_uri.path[1..-1]) end |