class OmniAuth::Strategies::ScanSnap

Constants

MAX_STATE_LENGTH

Public Instance Methods

authorization() click to toggle source
# File lib/omniauth/strategies/scansnap.rb, line 37
def authorization
  raw = "#{options[:client_id]}:#{options[:client_secret]}"
  encoded = Base64.strict_encode64(raw)
  "Basic #{encoded}"
end
setup_phase() click to toggle source
# File lib/omniauth/strategies/scansnap.rb, line 10
def setup_phase
  options[:client_options].merge!(
    site: site,
    authorize_url: '/oauth2/authorize',
    token_url: '/api/oauth2/token'
  )

  options[:token_params][:headers] = { 'Authorization' => authorization }

  options[:state] = SecureRandom.hex(MAX_STATE_LENGTH / 2)
end
site() click to toggle source
# File lib/omniauth/strategies/scansnap.rb, line 26
def site
  country = options.delete(:country)
  language = options.delete(:language)
  locale = language ? "#{language}_#{country}" : country
  region_api_uri = options.delete(:region_api_uri) || "https://api.cloud.scansnap.com/api/region/"

  response = Faraday.get("#{region_api_uri}#{locale}")
  body = JSON.parse(response.body)
  body['auth_url']
end