Class: CognitiveFaculty::Configuration::Auth
- Inherits:
-
Object
- Object
- CognitiveFaculty::Configuration::Auth
- Defined in:
- lib/cognitive_faculty/configuration/auth.rb
Overview
Authorization configuration for Cognitive Faculty Platform API.
Attributes:
+client_id+: Client ID used to request an acces token.
+client_secret+: Client secret used to request an access token.
+tenant_id+: AppID tenant id
+oauth_server_url+: AppID oauth server URL
+token+: (read-only) OIDC access token.
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#oauth_server_url ⇒ Object
Returns the value of attribute oauth_server_url.
-
#tenant_id ⇒ Object
Returns the value of attribute tenant_id.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #access_token ⇒ Object
-
#initialize ⇒ Auth
constructor
A new instance of Auth.
- #update_token ⇒ Object
Constructor Details
#initialize ⇒ Auth
Returns a new instance of Auth.
19 20 21 |
# File 'lib/cognitive_faculty/configuration/auth.rb', line 19 def initialize @realm = "master" end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
16 17 18 |
# File 'lib/cognitive_faculty/configuration/auth.rb', line 16 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
16 17 18 |
# File 'lib/cognitive_faculty/configuration/auth.rb', line 16 def client_secret @client_secret end |
#oauth_server_url ⇒ Object
Returns the value of attribute oauth_server_url.
16 17 18 |
# File 'lib/cognitive_faculty/configuration/auth.rb', line 16 def oauth_server_url @oauth_server_url end |
#tenant_id ⇒ Object
Returns the value of attribute tenant_id.
16 17 18 |
# File 'lib/cognitive_faculty/configuration/auth.rb', line 16 def tenant_id @tenant_id end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
17 18 19 |
# File 'lib/cognitive_faculty/configuration/auth.rb', line 17 def token @token end |
Instance Method Details
#access_token ⇒ Object
23 24 25 26 |
# File 'lib/cognitive_faculty/configuration/auth.rb', line 23 def access_token update_token if token.nil? || token.expired? token.token end |
#update_token ⇒ Object
28 29 30 31 32 |
# File 'lib/cognitive_faculty/configuration/auth.rb', line 28 def update_token opts = { token_url: "#{oauth_server_url}/token" } oauth2 = OAuth2::Client.new(client_id, client_secret, opts) @token = oauth2.client_credentials.get_token(:username => client_id, :password => client_secret) end |