Class: MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(access_token_provider) ⇒ BaseBearerTokenAuthenticationProvider

Returns a new instance of BaseBearerTokenAuthenticationProvider.

Raises:

  • (StandardError)


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

Raises:

  • (StandardError)


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.get_authorization_token(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