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
56 57 58 59 |
# File 'lib/bwapi/client/oauth.rb', line 56 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
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bwapi/client/oauth.rb', line 39 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
64 65 66 67 68 69 70 |
# File 'lib/bwapi/client/oauth.rb', line 64 def oauth_request(opts = {}) creds = post 'oauth/token', opts self.access_token = creds.access_token self.expires_in = creds.expires_in self.refresh_token = creds.refresh_token if application_client? creds end |
#oauth_token(opts = {}) ⇒ Object Also known as: login
Authenticate a user
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bwapi/client/oauth.rb', line 16 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 |