Class: Redd::AuthStrategies::Web
- Inherits:
-
AuthStrategy
- Object
- Client
- AuthStrategy
- Redd::AuthStrategies::Web
- Defined in:
- lib/redd/auth_strategies/web.rb
Overview
A typical code-based authentication, for ‘web’ and ‘installed’ types.
Constant Summary
Constants inherited from AuthStrategy
Constants inherited from Client
Instance Method Summary collapse
-
#authenticate(code) ⇒ Access
Authenticate with a code using the “web” flow.
-
#initialize(client_id:, redirect_uri:, secret: '', **kwargs) ⇒ Web
constructor
A new instance of Web.
-
#refresh(access) ⇒ Access
Refresh the authentication and return a new refreshed access.
Methods inherited from AuthStrategy
Methods inherited from Client
#delete, #get, #patch, #post, #put, #request
Constructor Details
#initialize(client_id:, redirect_uri:, secret: '', **kwargs) ⇒ Web
Returns a new instance of Web.
9 10 11 12 |
# File 'lib/redd/auth_strategies/web.rb', line 9 def initialize(client_id:, redirect_uri:, secret: '', **kwargs) super(client_id: client_id, secret: secret, **kwargs) @redirect_uri = redirect_uri end |
Instance Method Details
#authenticate(code) ⇒ Access
Authenticate with a code using the “web” flow.
17 18 19 |
# File 'lib/redd/auth_strategies/web.rb', line 17 def authenticate(code) request_access('authorization_code', code: code, redirect_uri: @redirect_uri) end |
#refresh(access) ⇒ Access
Refresh the authentication and return a new refreshed access
23 24 25 26 27 28 |
# File 'lib/redd/auth_strategies/web.rb', line 23 def refresh(access) token = access.is_a?(String) ? refresh_token : access.refresh_token response = post('/api/v1/access_token', grant_type: 'refresh_token', refresh_token: token) # When refreshed, the response doesn't include an access token, so we have to add it. Models::Access.new(self, response.body.merge(refresh_token: token)) end |