Module: BWAPI::Client::OAuth
- Included in:
- BWAPI::Client
- Defined in:
- lib/bwapi/client/oauth.rb
Overview
OAuth module for oauth/token endpoint
Instance Method Summary collapse
-
#determine_grant_type ⇒ String
Determines grant-type used for client.
-
#oauth_refresh_token(opts = {}) ⇒ Object
(also: #refresh)
Refresh a authenticated users oauth_token.
-
#oauth_request(opts = {}) ⇒ Object
Sends a oauth request.
-
#oauth_token(opts = {}) ⇒ Object
(also: #login)
Authenticate a user.
Instance Method Details
#determine_grant_type ⇒ String
Determines grant-type used for client
54 55 56 57 |
# File 'lib/bwapi/client/oauth.rb', line 54 def determine_grant_type return grant_type unless grant_type.nil? api_client? ? 'api-password' : 'password' end |
#oauth_refresh_token(opts = {}) ⇒ Object Also known as: refresh
Refresh a authenticated users oauth_token
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bwapi/client/oauth.rb', line 37 def oauth_refresh_token(opts = {}) opts = { username: username, password: password, refresh_token: refresh_token, grant_type: 'refresh_token', client_id: client_id, force_urlencoded: true }.merge opts oauth_request opts end |
#oauth_request(opts = {}) ⇒ Object
Sends a oauth request
62 63 64 65 66 67 68 |
# File 'lib/bwapi/client/oauth.rb', line 62 def oauth_request(opts = {}) response = post('oauth/token', opts) self.access_token = response['access_token'] self.access_token_expiry = Time.at(Time.now.to_i + response['expires_in']).iso8601 self.refresh_token = response['refresh_token'] if application_client? response end |
#oauth_token(opts = {}) ⇒ Object Also known as: login
Authenticate a user
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bwapi/client/oauth.rb', line 14 def oauth_token(opts = {}) opts = { username: username, password: password, grant_type: determine_grant_type, client_secret: client_secret, client_id: client_id, force_urlencoded: true }.merge opts oauth_request opts end |