This repository was archived by the owner on Jan 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ru
61 lines (48 loc) · 1.42 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
if File.exist? '.env'
require 'dotenv'
Dotenv.load
end
# Ensure everything is set up for authentication
fail 'Missing GITHUB_KEY' unless ENV['GITHUB_KEY']
fail 'Missing GITHUB_SECRET' unless ENV['GITHUB_SECRET']
fail 'Missing GITHUB_ORG_ID' unless ENV['GITHUB_ORG_ID']
require 'sinatra/cyclist'
require 'omniauth/strategies/github'
require 'octokit'
require 'dashing'
configure do
set :auth_token, ENV['DASHING_AUTH_TOKEN']
set :routes_to_cycle_through, [:seatshare_001, :seatshare_002]
set :cycle_duration, 35
set :default_dashboard, '_cycle'
helpers do
def protected!
redirect '/auth/github' unless session[:user_id]
end
end
use Rack::Session::Cookie
use OmniAuth::Builder do
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], scope: 'read:org'
end
get '/auth/github/callback' do
organization_id = ENV['GITHUB_ORG_ID'].to_i
auth = request.env['omniauth.auth']
client = Octokit::Client.new access_token: auth['credentials']['token']
user_orgs = client.user.rels[:organizations].get.data
puts 'inspecting ...'
puts user_orgs.inspect
if user_orgs.any? { |org| org.id == organization_id }
session[:user_id] = auth['info']['email']
redirect '/'
else
redirect '/auth/failure'
end
end
get '/auth/failure' do
'Nope.'
end
end
map Sinatra::Application.assets_prefix do
run Sinatra::Application.sprockets
end
run Sinatra::Application