Class: MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext
- Inherits:
-
OAuthContext
- Object
- OAuthContext
- MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext
- Defined in:
- lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb
Overview
Token request context class for the authorization code grant type.
Instance Attribute Summary collapse
-
#additional_params ⇒ Object
readonly
Returns the value of attribute additional_params.
-
#auth_code ⇒ Object
Returns the value of attribute auth_code.
-
#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.
-
#redirect_uri ⇒ Object
readonly
Returns the value of attribute redirect_uri.
-
#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
-
#generate_authorize_url(scopes, additional_params = {}) ⇒ Object
This function generates an authorize URL for obtaining the auth code.
- #get_token ⇒ Object
-
#initialize(tenant_id, client_id, client_secret, redirect_uri, auth_code = nil) ⇒ AuthorizationCodeContext
constructor
This is the initializer for AuthorizationCodeContext, the token request context when using the authorization code grant flow.
- #initialize_oauth_provider ⇒ Object
- #initialize_scopes(scopes) ⇒ Object
Methods included from OAuthCustomFlow
get_oauth_provider, get_scopes, get_token
Constructor Details
#initialize(tenant_id, client_id, client_secret, redirect_uri, auth_code = nil) ⇒ AuthorizationCodeContext
This is the initializer for AuthorizationCodeContext, the token request context when using the authorization code 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
redirect_uri: a string containing redirect_uri
auth_code: a string containting the auth code; default is nil, can be updated post-initialization
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb', line 21 def initialize(tenant_id, client_id, client_secret, redirect_uri, auth_code = nil) raise StandardError, 'redirect_uri cannot be nil/empty' if redirect_uri.nil? || redirect_uri.empty? @tenant_id = tenant_id @client_id = client_id @client_secret = client_secret @auth_code = auth_code @redirect_uri = redirect_uri @scopes = nil @oauth_provider = nil @grant_type = 'authorization code' 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/authorization_code_context.rb', line 9 def additional_params @additional_params end |
#auth_code ⇒ Object
Returns the value of attribute auth_code.
9 10 11 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb', line 9 def auth_code @auth_code end |
#client_id ⇒ Object
Returns the value of attribute client_id.
9 10 11 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_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/authorization_code_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/authorization_code_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/authorization_code_context.rb', line 9 def oauth_provider @oauth_provider end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
9 10 11 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb', line 9 def redirect_uri @redirect_uri end |
#scopes=(value) ⇒ Object (writeonly)
Sets the attribute scopes
11 12 13 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb', line 11 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/authorization_code_context.rb', line 9 def tenant_id @tenant_id end |
Instance Method Details
#generate_authorize_url(scopes, additional_params = {}) ⇒ Object
This function generates an authorize URL for obtaining the auth code. :params
scopes: an array of stings, where each string is a scope
additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' }
default is empty hash
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb', line 50 def (scopes, additional_params = {}) @additional_params = additional_params self.initialize_scopes(scopes) self.initialize_oauth_provider parameters = { scope: @scopes, redirect_uri: @redirect_uri, access_type: 'offline', prompt: 'consent'} parameters = parameters.merge(additional_params) @oauth_provider.auth_code.(parameters) end |
#get_token ⇒ Object
61 62 63 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb', line 61 def get_token @oauth_provider.auth_code.get_token(@auth_code, redirect_uri: @redirect_uri) end |
#initialize_oauth_provider ⇒ Object
65 66 67 68 69 70 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb', line 65 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
72 73 74 75 76 77 78 79 80 |
# File 'lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb', line 72 def initialize_scopes(scopes) scope_str = '' scopes.each { |scope| scope_str += scope + ' '} raise StandardError, 'scopes cannot be empty/nil.' if scope_str.empty? scope_str = 'offline_access ' + scope_str @scopes = scope_str end |