Class: OmniAuth::Strategies::ScanSnap

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

Constant Summary collapse

MAX_STATE_LENGTH =
36

Instance Method Summary collapse

Instance Method Details

#authorizationObject



37
38
39
40
41
# 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_phaseObject



10
11
12
13
14
15
16
17
18
19
20
# 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

#siteObject



26
27
28
29
30
31
32
33
34
35
# 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