Class: MsRestAzure::ApplicationTokenProvider

Inherits:
MsRest::TokenProvider
  • Object
show all
Defined in:
lib/ms_rest_azure/credentials/application_token_provider.rb

Overview

Class that provides access to authentication token.

Instance Method Summary collapse

Constructor Details

#initialize(tenant_id, client_id, client_secret, settings = ActiveDirectoryServiceSettings.get_azure_settings) ⇒ ApplicationTokenProvider

Creates and initialize new instance of the ApplicationTokenProvider class.

Parameters:

  • tenant_id (String)

    tenant id (also known as domain).

  • client_id (String)

    client id.

  • client_secret (String)

    client secret.

  • settings (ActiveDirectoryServiceSettings) (defaults to: ActiveDirectoryServiceSettings.get_azure_settings)

    client secret.



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ms_rest_azure/credentials/application_token_provider.rb', line 49

def initialize(tenant_id, client_id, client_secret, settings = ActiveDirectoryServiceSettings.get_azure_settings)
  fail ArgumentError, 'Tenant id cannot be nil' if tenant_id.nil?
  fail ArgumentError, 'Client id cannot be nil' if client_id.nil?
  fail ArgumentError, 'Client secret key cannot be nil' if client_secret.nil?
  fail ArgumentError, 'Azure AD settings cannot be nil' if settings.nil?

  @tenant_id = tenant_id
  @client_id = client_id
  @client_secret = client_secret
  @settings = settings

  @expiration_threshold = 5 * 60
end

Instance Method Details

#get_authentication_headerString

Returns the string value which needs to be attached to HTTP request header in order to be authorized.

Returns:

  • (String)

    authentication headers.



68
69
70
71
# File 'lib/ms_rest_azure/credentials/application_token_provider.rb', line 68

def get_authentication_header
  acquire_token if token_expired
  "#{token_type} #{token}"
end