Class: OmniAuth::Strategies::LightspeedOauth2

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

Overview

OmniAuth strategy for Lightspeed Restaurant (K-Series) OAuth2.

Lightspeed uses OpenID Connect (Keycloak) with standard OAuth2 Authorization Code Grant. Access tokens expire; use refresh tokens to obtain new pairs.

Demo/Trial: auth.lsk-demo.app, api.trial.lsk.lightspeed.app Production: auth.lsk-prod.app, api.lsk.lightspeed.app

Examples:

Basic usage

provider :lightspeed_oauth2, ENV['LIGHTSPEED_CLIENT_ID'], ENV['LIGHTSPEED_CLIENT_SECRET']

With custom environment

provider :lightspeed_oauth2, ENV['LIGHTSPEED_CLIENT_ID'], ENV['LIGHTSPEED_CLIENT_SECRET'],
  environment: :production

Constant Summary collapse

ENVIRONMENTS =
{
  trial: {
    site: 'https://api.trial.lsk.lightspeed.app',
    authorize_url: 'https://auth.lsk-demo.app/realms/k-series/protocol/openid-connect/auth',
    token_url: 'https://auth.lsk-demo.app/realms/k-series/protocol/openid-connect/token'
  },
  production: {
    site: 'https://api.lsk.lightspeed.app',
    authorize_url: 'https://auth.lsk-prod.app/realms/k-series/protocol/openid-connect/auth',
    token_url: 'https://auth.lsk-prod.app/realms/k-series/protocol/openid-connect/token'
  }
}.freeze

Instance Method Summary collapse

Instance Method Details

#build_access_tokenObject

Override to strip query params from callback_url for redirect_uri matching.



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/omniauth/strategies/lightspeed_oauth2.rb', line 83

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



78
79
80
# File 'lib/omniauth/strategies/lightspeed_oauth2.rb', line 78

def raw_info
  @raw_info ||= fetch_business_info
end

#setup_phaseObject



53
54
55
56
57
58
# File 'lib/omniauth/strategies/lightspeed_oauth2.rb', line 53

def setup_phase
  env = options[:environment]&.to_sym || :trial
  urls = ENVIRONMENTS.fetch(env, ENVIRONMENTS[:trial])
  options.client_options.merge!(urls)
  super
end