Class: MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext
- Inherits:
-
OAuthContext
- Object
- OAuthContext
- MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext
- Defined in:
- lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb
Overview
Token request context class for the client credential grant type.
Instance Attribute Summary collapse
-
#additional_params ⇒ Object
readonly
Returns the value of attribute additional_params.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#grant_type ⇒ Object
readonly
Returns the value of attribute grant_type.
-
#oauth_provider ⇒ Object
readonly
Returns the value of attribute oauth_provider.
-
#scopes ⇒ Object
writeonly
Sets the attribute scopes.
-
#tenant_id ⇒ Object
readonly
Returns the value of attribute tenant_id.
Attributes inherited from OAuthContext
Instance Method Summary collapse
- #get_token ⇒ Object
-
#initialize(tenant_id, client_id, client_secret, additional_params = {}) ⇒ ClientCredentialContext
constructor
This is the initializer for ClientCredentialContext, the token request context when using the client credential grant flow.
- #initialize_oauth_provider ⇒ Object
-
#initialize_scopes(scopes = []) ⇒ Object
Function to initialize the scope for the client credential context object.
Methods included from OAuthCustomFlow
get_oauth_provider, get_scopes, get_token
Constructor Details
#initialize(tenant_id, client_id, client_secret, additional_params = {}) ⇒ ClientCredentialContext
This is the initializer for ClientCredentialContext, the token request context when using the client credential grant flow. :params
tenant_id: a string containing the tenant id
client_id: a string containing the client id
client_secret: a string containing the client secret
additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' }
default is empty hash
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb', line 20 def initialize(tenant_id, client_id, client_secret, additional_params = {}) @tenant_id = tenant_id @client_id = client_id @client_secret = client_secret @additional_params = additional_params @scopes = nil @oauth_provider = nil @grant_type = 'client credential' if @tenant_id.nil? || @client_id.nil? || @client_secret.nil? || @tenant_id.empty? || @client_id.empty? || @client_secret.empty? raise StandardError, 'tenant_id, client_id and client_secret cannot be empty' end end |
Instance Attribute Details
#additional_params ⇒ Object
Returns the value of attribute additional_params.
9 10 11 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb', line 9 def additional_params @additional_params end |
#client_id ⇒ Object
Returns the value of attribute client_id.
9 10 11 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb', line 9 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
9 10 11 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb', line 9 def client_secret @client_secret end |
#grant_type ⇒ Object
Returns the value of attribute grant_type.
9 10 11 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb', line 9 def grant_type @grant_type end |
#oauth_provider ⇒ Object
Returns the value of attribute oauth_provider.
9 10 11 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb', line 9 def oauth_provider @oauth_provider end |
#scopes=(value) ⇒ Object (writeonly)
Sets the attribute scopes
10 11 12 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb', line 10 def scopes=(value) @scopes = value end |
#tenant_id ⇒ Object
Returns the value of attribute tenant_id.
9 10 11 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb', line 9 def tenant_id @tenant_id end |
Instance Method Details
#get_token ⇒ Object
35 36 37 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb', line 35 def get_token @oauth_provider.client_credentials.get_token({ scope: @scopes }) end |
#initialize_oauth_provider ⇒ Object
39 40 41 42 43 44 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb', line 39 def initialize_oauth_provider @oauth_provider = OAuth2::Client.new(@client_id, @client_secret, site: 'https://login.microsoftonline.com', authorize_url: "/#{@tenant_id}/oauth2/v2.0/authorize", token_url: "/#{@tenant_id}/oauth2/v2.0/token") end |
#initialize_scopes(scopes = []) ⇒ Object
Function to initialize the scope for the client credential context object. Only a single scope is supported for this flow and it’s expected to be schme://service/.default
48 49 50 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb', line 48 def initialize_scopes(scopes = []) @scopes = scopes[0] unless scopes.empty? end |