Class: VAAS::ResourceOwnerPasswordGrantAuthenticator
- Inherits:
-
Object
- Object
- VAAS::ResourceOwnerPasswordGrantAuthenticator
- Defined in:
- lib/vaas/resource_owner_password_grant_authenticator.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#password ⇒ Object
Returns the value of attribute password.
-
#token ⇒ Object
Returns the value of attribute token.
-
#token_endpoint ⇒ Object
Returns the value of attribute token_endpoint.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #get_token ⇒ Object
-
#initialize(client_id, username, password, token_endpoint = 'https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token') ⇒ ResourceOwnerPasswordGrantAuthenticator
constructor
A new instance of ResourceOwnerPasswordGrantAuthenticator.
Constructor Details
#initialize(client_id, username, password, token_endpoint = 'https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token') ⇒ ResourceOwnerPasswordGrantAuthenticator
Returns a new instance of ResourceOwnerPasswordGrantAuthenticator.
10 11 12 13 14 15 |
# File 'lib/vaas/resource_owner_password_grant_authenticator.rb', line 10 def initialize(client_id, username, password, token_endpoint = 'https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token') @client_id = client_id @username = username @password = password @token_endpoint = token_endpoint end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
8 9 10 |
# File 'lib/vaas/resource_owner_password_grant_authenticator.rb', line 8 def client_id @client_id end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'lib/vaas/resource_owner_password_grant_authenticator.rb', line 8 def password @password end |
#token ⇒ Object
Returns the value of attribute token.
8 9 10 |
# File 'lib/vaas/resource_owner_password_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/resource_owner_password_grant_authenticator.rb', line 8 def token_endpoint @token_endpoint end |
#username ⇒ Object
Returns the value of attribute username.
8 9 10 |
# File 'lib/vaas/resource_owner_password_grant_authenticator.rb', line 8 def username @username end |
Instance Method Details
#get_token ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vaas/resource_owner_password_grant_authenticator.rb', line 17 def get_token Async do client = Async::HTTP::Internet.new header = [['content-type', 'application/x-www-form-urlencoded']] body = ["grant_type=password&client_id=#{client_id}&username=#{username}&password=#{password}"] 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 |