Class: MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider
- Inherits:
-
Object
- Object
- MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider
- Includes:
- AuthenticationProvider
- Defined in:
- lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb
Overview
Provides a base class for implementing AuthenticationProvider for Bearer token scheme
Constant Summary collapse
- AUTHORIZATION_HEADER_KEY =
'Authorization'
Instance Method Summary collapse
- #authenticate_request(request, additional_properties = {}) ⇒ Object
-
#initialize(access_token_provider) ⇒ BaseBearerTokenAuthenticationProvider
constructor
A new instance of BaseBearerTokenAuthenticationProvider.
Constructor Details
#initialize(access_token_provider) ⇒ BaseBearerTokenAuthenticationProvider
Returns a new instance of BaseBearerTokenAuthenticationProvider.
10 11 12 13 14 |
# File 'lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb', line 10 def initialize(access_token_provider) raise StandardError, 'access_token_provider parameter cannot be nil' if access_token_provider.nil? @access_token_provider = access_token_provider end |
Instance Method Details
#authenticate_request(request, additional_properties = {}) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb', line 17 def authenticate_request(request, additional_properties = {}) raise StandardError, 'Request cannot be null' if request.nil? Fiber.new do token = @access_token_provider.(request.uri, additional_properties).resume request.headers.add(AUTHORIZATION_HEADER_KEY, "Bearer #{token}") unless token.nil? || token.empty? end unless request.headers.get_all.key?(AUTHORIZATION_HEADER_KEY) end |