This repository has been archived by the owner on Oct 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
config.ru
100 lines (86 loc) · 2.01 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
require "rubygems"
require "bundler/setup"
require 'rack/ssl'
require 'sinatra/auth/github'
module Example
class BadAuthentication < Sinatra::Base
get '/unauthenticated' do
status 403
<<-EOS
<h2>Unable to authenticate, sorry bud.</h2>
<p>#{env['warden'].message}</p>
EOS
end
end
class SimpleApp < Sinatra::Base
enable :sessions
enable :raise_errors
disable :show_exceptions
enable :inline_templates
set :github_options, {
:scope => 'user',
:secret => ENV['GITHUB_CLIENT_SECRET'] || 'test_client_secret',
:client_id => ENV['GITHUB_CLIENT_ID'] || 'test_client_id'
}
register Sinatra::Auth::Github
get '/' do
erb :index
end
get '/profile' do
authenticate!
erb :profile
end
get '/login' do
authenticate!
redirect '/'
end
get '/logout' do
logout!
redirect '/'
end
end
def self.app
@app ||= Rack::Builder.new do
run SimpleApp
end
end
end
use Rack::SSL if ENV['RAILS_ENV'] == "production"
run Example.app
__END__
@@ layout
<html>
<body>
<h1>Simple App Example</h1>
<ul>
<li><a href='/'>Home</a></li>
<li><a href='/profile'>View profile</a><% if !env['warden'].authenticated? %> (implicit sign in)<% end %></li>
<% if authenticated? %>
<li><a href='/logout'>Sign out</a></li>
<% else %>
<li><a href='/login'>Sign in</a> (explicit sign in)</li>
<% end %>
</ul>
<hr />
<%= yield %>
</body>
</html>
@@ index
<% if authenticated? %>
<h2>
<img src='<%= env['warden'].user.avatar_url %>' />
Welcome <%= github_user.name %>
</h2>
<% else %>
<h2>Welcome stranger</h2>
<% end %>
@@ profile
<h2>Profile</h2>
<dl>
<dt>Rails Org Member:</dt>
<dd><%= github_organization_access?('rails') %></dd>
<dt>Publicized Rails Org Member:</dt>
<dd><%= github_public_organization_access?('rails') %></dd>
<dt>Rails Committer Team Member:</dt>
<dd><%= github_team_access?(632) %></dd>
</dl>