class Redd::AuthStrategies::Web

A typical code-based authentication, for 'web' and 'installed' types.

Public Class Methods

new(client_id:, redirect_uri:, secret: '', **kwargs) click to toggle source
Calls superclass method Redd::AuthStrategies::AuthStrategy::new
# 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

Public Instance Methods

authenticate(code) click to toggle source

Authenticate with a code using the “web” flow. @param code [String] the code returned by reddit @return [Access]

# 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) click to toggle source

Refresh the authentication and return a new refreshed access @return [Access] the new access

# 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