/
config.ru
44 lines (33 loc) · 1.02 KB
/
config.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env ruby
require "rack"
require 'chaplin'
require 'omniauth-github'
class OmniAuthForwarder
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
request.update_param('cookies', request.cookies)
if env['omniauth.auth']
env["QUERY_STRING"] = Rack::Utils.build_query({auth: env['omniauth.auth'].to_h})
env["rack.request.query_string"] = Rack::Utils.build_query({auth: env['omniauth.auth'].to_h})
env["rack.request.query_hash"] = {auth: env['omniauth.auth'].to_h}
end
response = @app.call(env)
response = Rack::Response.new(response[2], response[0], response[1])
if env['omniauth.auth']
response.set_cookie("token", {
path: '/',
value: env['omniauth.auth']['credentials']['token']
})
end
response.finish
end
end
use Rack::Session::Cookie
use OmniAuth::Builder do
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], scope: "user"
end
use OmniAuthForwarder
run Chaplin.new(Dir.pwd + "/dist").server