Class: MicrosoftKiotaAuthenticationOAuth::OAuthAccessTokenProvider
- Inherits:
-
Object
- Object
- MicrosoftKiotaAuthenticationOAuth::OAuthAccessTokenProvider
- Defined in:
- lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb
Overview
Access Token Provider class implementation
Instance Attribute Summary collapse
-
#host_validator ⇒ Object
readonly
Returns the value of attribute host_validator.
-
#scopes ⇒ Object
readonly
Returns the value of attribute scopes.
Instance Method Summary collapse
-
#get_authorization_token(uri, additional_properties = {}) ⇒ Object
This function obtains the authorization token.
-
#initialize(token_request_context, allowed_hosts = [], scopes = []) ⇒ OAuthAccessTokenProvider
constructor
This is the initializer for OAuthAccessTokenProvider.
Constructor Details
#initialize(token_request_context, allowed_hosts = [], scopes = []) ⇒ OAuthAccessTokenProvider
This is the initializer for OAuthAccessTokenProvider. :params
token_request_context: a instance of one of our token request context or a custom implementation
allowed_hosts: an array of strings, where each string is an allowed host, default is empty
scopes: an array of strings, where each string is a scope, default is empty array
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb', line 20 def initialize(token_request_context, allowed_hosts = [], scopes = []) raise StandardError, 'Parameter token_request_context cannot be nil.' if token_request_context.nil? @token_request_context = token_request_context unless @token_request_context.is_a?(MicrosoftKiotaAuthenticationOAuth::OAuthContext) raise StandardError, 'Parameter token_request_context must be an instance of one of our grant flow context classes.' end @cached_token = nil @host_validator = if allowed_hosts.nil? || allowed_hosts.size.zero? MicrsoftKiotaAbstractions::AllowedHostsValidator.new(['graph.microsoft.com', 'graph.microsoft.us', 'dod-graph.microsoft.us', 'graph.microsoft.de', 'microsoftgraph.chinacloudapi.cn', 'canary.graph.microsoft.com']) else MicrosoftKiotaAbstractions::AllowedHostsValidator.new(allowed_hosts) end @token_request_context.initialize_oauth_provider @token_request_context.initialize_scopes(scopes) end |
Instance Attribute Details
#host_validator ⇒ Object
Returns the value of attribute host_validator.
74 75 76 |
# File 'lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb', line 74 def host_validator @host_validator end |
#scopes ⇒ Object
Returns the value of attribute scopes.
74 75 76 |
# File 'lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb', line 74 def scopes @scopes end |
Instance Method Details
#get_authorization_token(uri, additional_properties = {}) ⇒ Object
This function obtains the authorization token. :params
uri: a string containing the uri
additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' }
default is empty hash
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb', line 47 def (uri, additional_properties = {}) return nil if !uri || !@host_validator.url_host_valid?(uri) parsed_url = URI(uri) raise StandardError, 'Only https is supported' if parsed_url.scheme != 'https' Fiber.new do if @cached_token token = OAuth2::AccessToken.from_hash(@token_request_context.oauth_provider, @cached_token) return token.token if !token.nil? && !token.expired? if token.expired? token = token.refresh! @cached_token = token.to_hash return token.token end end token = nil token = @token_request_context.get_token @cached_token = token.to_hash unless token.nil? return token.token unless token.nil? end end |