require 'bundler/setup' require 'sinatra/base' require 'omniauth-duodealer-oauth2' SCOPE = 'read_products,read_orders,read_customers,write_shipping' DUODEALER_API_KEY = ENV['DUODEALER_API_KEY'] DUODEALER_SHARED_SECRET = ENV['DUODEALER_SHARED_SECRET'] unless DUODEALER_API_KEY && DUODEALER_SHARED_SECRET abort("DUODEALER_API_KEY and DUODEALER_SHARED_SECRET environment variables must be set") end class App < Sinatra::Base get '/' do <<-HTML DuoDealer Oauth2
HTML end get '/auth/:provider/callback' do <<-HTML DuoDealer Oauth2

Authorized

Shop: #{request.env['omniauth.auth'].uid}

Token: #{request.env['omniauth.auth']['credentials']['token']}

HTML end get '/auth/failure' do <<-HTML DuoDealer Oauth2

Failed Authorization

Message: #{params[:message]}

HTML end end use Rack::Session::Cookie, secret: SecureRandom.hex(64) use OmniAuth::Builder do provider :duodealer, DUODEALER_API_KEY, DUODEALER_SHARED_SECRET, :scope => SCOPE end run App.new