Class: VAAS::ClientCredentialsGrantAuthenticator
- Inherits:
-
Object
- Object
- VAAS::ClientCredentialsGrantAuthenticator
- Defined in:
- lib/vaas/client_credentials_grant_authenticator.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#token ⇒ Object
Returns the value of attribute token.
-
#token_endpoint ⇒ Object
Returns the value of attribute token_endpoint.
Instance Method Summary collapse
- #get_token ⇒ Object
-
#initialize(client_id, client_secret, token_endpoint = 'https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token') ⇒ ClientCredentialsGrantAuthenticator
constructor
A new instance of ClientCredentialsGrantAuthenticator.
Constructor Details
#initialize(client_id, client_secret, token_endpoint = 'https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token') ⇒ ClientCredentialsGrantAuthenticator
Returns a new instance of ClientCredentialsGrantAuthenticator.
10 11 12 13 14 |
# File 'lib/vaas/client_credentials_grant_authenticator.rb', line 10 def initialize(client_id, client_secret, token_endpoint = 'https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token') @client_id = client_id @client_secret = client_secret @token_endpoint = token_endpoint end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
8 9 10 |
# File 'lib/vaas/client_credentials_grant_authenticator.rb', line 8 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
8 9 10 |
# File 'lib/vaas/client_credentials_grant_authenticator.rb', line 8 def client_secret @client_secret end |
#token ⇒ Object
Returns the value of attribute token.
8 9 10 |
# File 'lib/vaas/client_credentials_grant_authenticator.rb', line 8 def token @token end |
#token_endpoint ⇒ Object
Returns the value of attribute token_endpoint.
8 9 10 |
# File 'lib/vaas/client_credentials_grant_authenticator.rb', line 8 def token_endpoint @token_endpoint end |
Instance Method Details
#get_token ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vaas/client_credentials_grant_authenticator.rb', line 16 def get_token Async do client = Async::HTTP::Internet.new header = [['content-type', 'application/x-www-form-urlencoded']] body = ["grant_type=client_credentials&client_id=#{client_id}&client_secret=#{client_secret}"] response = client.post(token_endpoint, header, body) self.token = JSON.parse(response.read)['access_token'] rescue => e raise VaasAuthenticationError, e ensure client&.close end raise VaasAuthenticationError if token.nil? token end |