#!/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"}, ["Sign in with e-klase"]] 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)