Class: OmniAuth::Strategies::GustoOauth2

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/gusto_oauth2.rb

Overview

OmniAuth strategy for Gusto OAuth2.

Gusto uses standard OAuth2 with 2-hour access tokens and single-use refresh tokens. The authorize and token endpoints are on api.gusto.com. User info is fetched via GET /v1/me.

Examples:

Basic usage

provider :gusto_oauth2, ENV['GUSTO_CLIENT_ID'], ENV['GUSTO_CLIENT_SECRET']

With Devise

config.omniauth :gusto_oauth2, ENV['GUSTO_CLIENT_ID'], ENV['GUSTO_CLIENT_SECRET']

Instance Method Summary collapse

Instance Method Details

#build_access_tokenObject

Override to strip query params from callback_url for redirect_uri matching. Gusto requires the redirect_uri to match exactly.



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/omniauth/strategies/gusto_oauth2.rb', line 54

def build_access_token
  redirect_uri = callback_url.sub(/\?.*/, '')
  log(:info, "Token exchange — site: #{client.site}, redirect_uri: #{redirect_uri}")
  verifier = request.params['code']
  client.auth_code.get_token(
    verifier,
    { redirect_uri: redirect_uri }.merge(token_params.to_hash(symbolize_keys: true)),
    deep_symbolize(options.auth_token_params)
  )
rescue ::OAuth2::Error => e
  log(:error, "Token exchange FAILED: status=#{e.response&.status} body=#{e.response&.body}")
  raise
end

#raw_infoObject



48
49
50
# File 'lib/omniauth/strategies/gusto_oauth2.rb', line 48

def raw_info
  @raw_info ||= fetch_user_and_company_info
end