Sha256: eaf134bfda35b361777084e14d7f03d8e8ce85eab569f0f4270578cdec992dcd

Contents?: true

Size: 1.5 KB

Versions: 15

Compression:

Stored size: 1.5 KB

Contents

require 'bundler/setup'
require 'sinatra/base'
require 'omniauth-shopify-oauth2'

SCOPE = 'read_products,read_orders,read_customers,write_shipping'
SHOPIFY_API_KEY = ENV['SHOPIFY_API_KEY']
SHOPIFY_SHARED_SECRET = ENV['SHOPIFY_SHARED_SECRET']

unless SHOPIFY_API_KEY && SHOPIFY_SHARED_SECRET
  abort("SHOPIFY_API_KEY and SHOPIFY_SHARED_SECRET environment variables must be set")
end

class App < Sinatra::Base
  get '/' do
    <<-HTML
    <html>
    <head>
      <title>Shopify Oauth2</title>
    </head>
    <body>
      <form action="/auth/shopify" method="get">
      <label for="shop">Enter your store's URL:</label>
      <input type="text" name="shop" placeholder="your-shop-url.myshopify.com">
      <button type="submit">Log In</button>
      </form>
    </body>
    </html>
    HTML
  end

  get '/auth/:provider/callback' do
    <<-HTML
    <html>
    <head>
      <title>Shopify Oauth2</title>
    </head>
    <body>
      <h3>Authorized</h3>
      <p>Shop: #{request.env['omniauth.auth'].uid}</p>
      <p>Token: #{request.env['omniauth.auth']['credentials']['token']}</p>
    </body>
    </html>
    HTML
  end

  get '/auth/failure' do
    <<-HTML
    <html>
    <head>
      <title>Shopify Oauth2</title>
    </head>
    <body>
      <h3>Failed Authorization</h3>
      <p>Message: #{params[:message]}</p>
    </body>
    </html>
    HTML
  end
end

use Rack::Session::Cookie, secret: SecureRandom.hex(64)

use OmniAuth::Builder do
  provider :shopify, SHOPIFY_API_KEY, SHOPIFY_SHARED_SECRET, :scope => SCOPE
end

run App.new

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
omniauth-shopify-oauth2-2.2.2 example/config.ru
omniauth-shopify-oauth2-2.2.1 example/config.ru
omniauth-shopify-oauth2-2.2.0 example/config.ru
omniauth-shopify-oauth2-2.1.0 example/config.ru
omniauth-shopify-oauth2-2.0.0 example/config.ru
omniauth-shopify-oauth2-1.2.1 example/config.ru
omniauth-shopify-oauth2-1.2.0 example/config.ru
omniauth-shopify-oauth2-1.1.17 example/config.ru
omniauth-shopify-oauth2-1.1.16 example/config.ru
omniauth-shopify-oauth2-1.1.15 example/config.ru
omniauth-shopify-oauth2-1.1.14 example/config.ru
omniauth-shopify-oauth2-1.1.13 example/config.ru
omniauth-shopify-oauth2-1.1.12 example/config.ru
omniauth-shopify-oauth2-1.1.11 example/config.ru
omniauth-shopify-oauth2-1.1.10 example/config.ru