-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.ru
43 lines (33 loc) · 1012 Bytes
/
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
require 'sinatra'
require 'omniauth'
require 'json'
class MyApplication < Sinatra::Base
use Rack::Session::Cookie, secret: '123'
STRATEGY = 'RemoteUser'
#use OmniAuth::Strategies::RemoteUser
#STRATEGY = 'developer'
use OmniAuth::Strategies::Developer
get '/login' do
redirect '/gitlab/auth/%s' % STRATEGY
end
get '/logout' do
session[:current_user] = nil
redirect '/'
end
post '/auth/:provider/callback' do
session[:current_user] = request.env['omniauth.auth']['uid']
session[:current_user_email] = request.env['omniauth.auth']['info']['email']
session[:current_user_nickname] = request.env['omniauth.auth']['info']['nickname']
redirect '/'
end
get '/' do
user = session[:current_user]
if user
info = "(%s → %s)" % [session[:current_user_email], session[:current_user_nickname]]
user + info + ' <a href="/logout">logout</a>'
else
'NOT AUTHENTICATED <a href="/login">login</a>'
end
end
end
run MyApplication