Class: ADAL::AuthenticationContext
- Inherits:
-
Object
- Object
- ADAL::AuthenticationContext
- Includes:
- RequestParameters, Util
- Defined in:
- lib/adal/authentication_context.rb
Overview
Retrieves authentication tokens from Azure Active Directory and ADFS services. For most users, this is the primary class to authenticate an application.
Constant Summary
Constants included from RequestParameters
RequestParameters::AAD_API_VERSION, RequestParameters::ASSERTION, RequestParameters::CLIENT_ASSERTION, RequestParameters::CLIENT_ASSERTION_TYPE, RequestParameters::CLIENT_ID, RequestParameters::CLIENT_REQUEST_ID, RequestParameters::CLIENT_RETURN_CLIENT_REQUEST_ID, RequestParameters::CLIENT_SECRET, RequestParameters::CODE, RequestParameters::FORM_POST, RequestParameters::GRANT_TYPE, RequestParameters::PASSWORD, RequestParameters::REDIRECT_URI, RequestParameters::REFRESH_TOKEN, RequestParameters::RESOURCE, RequestParameters::SCOPE, RequestParameters::UNIQUE_ID, RequestParameters::USERNAME, RequestParameters::USER_INFO
Instance Method Summary collapse
-
#acquire_token_for_client(resource, client_cred) ⇒ Object
Gets an access token with only the clients credentials and no user information.
-
#acquire_token_for_user(resource, client_cred, user) ⇒ Object
Gets an acccess token with a previously acquired user token.
-
#acquire_token_with_authorization_code(auth_code, redirect_uri, client_cred, resource = nil) ⇒ Object
Gets an access token with a previously acquire authorization code.
-
#acquire_token_with_refresh_token(refresh_token, client_cred, resource = nil) ⇒ Object
Gets an access token using a previously acquire refresh token.
-
#authorization_request_url(resource, client_id, redirect_uri, extra_query_params = {}) ⇒ Object
Constructs a URL for an authorization endpoint using query parameters.
-
#correlation_id=(value) ⇒ Object
Sets the correlation id that will be used in all future request headers and logs.
-
#initialize(authority_host = Authority::WORLD_WIDE_AUTHORITY, tenant = Authority::COMMON_TENANT, options = {}) ⇒ AuthenticationContext
constructor
Creates a new AuthenticationContext.
Methods included from Util
#fail_if_arguments_nil, #http, #string_hash
Constructor Details
#initialize(authority_host = Authority::WORLD_WIDE_AUTHORITY, tenant = Authority::COMMON_TENANT, options = {}) ⇒ AuthenticationContext
Creates a new AuthenticationContext.
55 56 57 58 59 60 61 62 |
# File 'lib/adal/authentication_context.rb', line 55 def initialize( = Authority::WORLD_WIDE_AUTHORITY, tenant = Authority::COMMON_TENANT, = {}) fail_if_arguments_nil(, tenant) = [:validate_authority] || false @authority = Authority.new(, tenant, ) @token_cache = [:token_cache] || MemoryCache.new end |
Instance Method Details
#acquire_token_for_client(resource, client_cred) ⇒ Object
Gets an access token with only the clients credentials and no user information.
76 77 78 79 |
# File 'lib/adal/authentication_context.rb', line 76 def acquire_token_for_client(resource, client_cred) fail_if_arguments_nil(resource, client_cred) token_request_for(client_cred).get_for_client(resource) end |
#acquire_token_for_user(resource, client_cred, user) ⇒ Object
Gets an acccess token with a previously acquired user token. Gets an access token for a specific user. This method is relevant for three authentication scenarios:
-
Username/Password flow:
Pass in the username and password wrapped in an ADAL::UserCredential.
-
On-Behalf-Of flow:
This allows web services to accept access tokens users and then exchange them for access tokens for a different resource. Note that to use this flow you must properly configure permissions settings in the Azure web portal. Pass in the access token wrapped in an ADAL::UserAssertion.
-
User Identifier flow:
This will not make any network connections but will merely check the cache for existing tokens matching the request.
147 148 149 150 151 |
# File 'lib/adal/authentication_context.rb', line 147 def acquire_token_for_user(resource, client_cred, user) fail_if_arguments_nil(resource, client_cred, user) token_request_for(client_cred) .get_with_user_credential(user, resource) end |
#acquire_token_with_authorization_code(auth_code, redirect_uri, client_cred, resource = nil) ⇒ Object
Gets an access token with a previously acquire authorization code.
95 96 97 98 99 100 |
# File 'lib/adal/authentication_context.rb', line 95 def ( auth_code, redirect_uri, client_cred, resource = nil) fail_if_arguments_nil(auth_code, redirect_uri, client_cred) token_request_for(client_cred) .(auth_code, redirect_uri, resource) end |
#acquire_token_with_refresh_token(refresh_token, client_cred, resource = nil) ⇒ Object
Gets an access token using a previously acquire refresh token.
113 114 115 116 117 118 |
# File 'lib/adal/authentication_context.rb', line 113 def acquire_token_with_refresh_token( refresh_token, client_cred, resource = nil) fail_if_arguments_nil(refresh_token, client_cred) token_request_for(client_cred) .get_with_refresh_token(refresh_token, resource) end |
#authorization_request_url(resource, client_id, redirect_uri, extra_query_params = {}) ⇒ Object
Constructs a URL for an authorization endpoint using query parameters.
165 166 167 168 169 170 171 172 173 174 |
# File 'lib/adal/authentication_context.rb', line 165 def ( resource, client_id, redirect_uri, extra_query_params = {}) @authority.( extra_query_params.reverse_merge( client_id: client_id, response_mode: FORM_POST, redirect_uri: redirect_uri, resource: resource, response_type: CODE)) end |
#correlation_id=(value) ⇒ Object
Sets the correlation id that will be used in all future request headers and logs.
182 183 184 |
# File 'lib/adal/authentication_context.rb', line 182 def correlation_id=(value) Logging.correlation_id = value end |