Sha256: 66f4a688a096de698bce1e52932fc32900f0acfc169ed724c748e0bf8f42686f

Contents?: true

Size: 945 Bytes

Versions: 2

Compression:

Stored size: 945 Bytes

Contents

#!/usr/bin/env ruby

unless ENV['CLIENT_ID'] && ENV['CLIENT_SECRET']
  STDERR.puts "Environment variables CLIENT_ID and CLIENT_SECRET are missing."
  exit 1
end

require "bundler/setup"
require "omniauth-eklase"
require "rack"
require "byebug"

class App
  def call(env)
    req = Rack::Request.new(env)
    puts req.path_info
    case req.path_info
    when %r{^/$}
      [200, {"Content-Type" => "text/html"}, ["<a href='/auth/eklase'>Sign in with e-klase</a>"]]
    when %r{^/auth/eklase/callback}
      auth = req.env['omniauth.auth']
      [200, {"Content-Type" => "text/html"}, [auth.to_hash.inspect]]
    else
      [404, {"Content-Type" => "text/html"}, ["Not found"]]
    end
  end
end

app = Rack::Builder.new do
  use Rack::CommonLogger
  use Rack::ShowExceptions
  use Rack::Session::Cookie
  use OmniAuth::Builder do
    provider :eklase, ENV['CLIENT_ID'], ENV['CLIENT_SECRET']
  end
  run App.new
end

Rack::Server.start(app: app)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
omniauth-eklase-2.0.0 bin/server
omniauth-eklase-1.0.0 bin/server