Commit ecf67888176d41e0bb87a35938108a1a08fbe71b
1 parent
7a681423
Exists in
master
and in
2 other branches
Deleting module Strategy
Showing
1 changed file
with
2 additions
and
121 deletions
Show diff stats
config.ru
... | ... | @@ -2,132 +2,13 @@ require 'sinatra' |
2 | 2 | require 'omniauth' |
3 | 3 | require 'json' |
4 | 4 | |
5 | -module OmniAuth | |
6 | - module Strategies | |
7 | - class RemoteUser | |
8 | - include OmniAuth::Strategy | |
9 | - | |
10 | - option :cookie, '_gitlab_session' | |
11 | - option :internal_cookie, '_remote_user' | |
12 | - | |
13 | - def call(env) | |
14 | - | |
15 | - remote_user = env['HTTP_REMOTE_USER'] | |
16 | - | |
17 | -# $stderr.puts('Remote-User: %s ' % (remote_user || '(none)')) | |
18 | - | |
19 | - # $stderr.puts('relative_url: %s ' % ( env['SCRIPT_NAME'] )) | |
20 | - # :script_name - Specifies application path relative to domain root. If provided, prepends application path. | |
21 | - # http://api.rubyonrails.org/classes/ActionDispatch/Routing/UrlFor.html | |
22 | - | |
23 | - session_user = __current_user(env) | |
24 | - | |
25 | - if ! is_in_logout? (env) | |
26 | - if remote_user | |
27 | - if session_user | |
28 | - if remote_user == session_user | |
29 | - super(env) | |
30 | - else | |
31 | - __logout(env) || super(env) | |
32 | - end | |
33 | - else | |
34 | - __login(env, remote_user) || super(env) | |
35 | - end | |
36 | - else | |
37 | - if session_user | |
38 | - __logout(env) || super(env) | |
39 | - else | |
40 | - super(env) | |
41 | - end | |
42 | - end | |
43 | - else | |
44 | - super env | |
45 | - end | |
46 | - end | |
47 | - | |
48 | - def __current_user(env) | |
49 | - request = Rack::Request.new(env) | |
50 | - request.cookies.has_key?(options.internal_cookie) && request.cookies[options.internal_cookie] | |
51 | - end | |
52 | - | |
53 | - def __logout(env) | |
54 | - request = Rack::Request.new(env) | |
55 | - response = redirect_if_not_logging_in(request, sign_out_path ) | |
56 | - if response | |
57 | - response.delete_cookie(options.cookie) | |
58 | - response.delete_cookie(options.internal_cookie) | |
59 | - response | |
60 | - end | |
61 | - end | |
62 | - | |
63 | - def __login(env, uid) | |
64 | - request = Rack::Request.new(env) | |
65 | - response = redirect_if_not_logging_in(request, auth_path ) | |
66 | - if response | |
67 | - response.set_cookie(options.internal_cookie, uid) | |
68 | - response | |
69 | - end | |
70 | - end | |
71 | - | |
72 | - def is_in_logout? (env) | |
73 | - request = Rack::Request.new(env) | |
74 | - request.path == sign_out_path | |
75 | - end | |
76 | - | |
77 | - def redirect_if_not_logging_in(request, url) | |
78 | - if ! [ | |
79 | - sign_out_path, | |
80 | - auth_path, | |
81 | - callback_path | |
82 | - ].include?(request.path_info) | |
83 | - response = Rack::Response.new | |
84 | - response.redirect url | |
85 | - response | |
86 | - end | |
87 | - end | |
88 | - | |
89 | - uid do | |
90 | - request.env['HTTP_REMOTE_USER'] | |
91 | - end | |
92 | - | |
93 | - info do | |
94 | - user_data = request.env['HTTP_REMOTE_USER_DATA'] | |
95 | - if user_data | |
96 | - data = JSON.parse(user_data) | |
97 | - data['nickname'] = data['name'] | |
98 | - data | |
99 | - else | |
100 | - {} | |
101 | - end | |
102 | - end | |
103 | - | |
104 | - def request_phase | |
105 | - redirect callback_path | |
106 | - end | |
107 | - | |
108 | - def callback_path | |
109 | - "#{auth_path}/callback" | |
110 | - end | |
111 | - | |
112 | - def auth_path | |
113 | - "#{path_prefix}/RemoteUser" | |
114 | - end | |
115 | - | |
116 | - def sign_out_path | |
117 | - '/users/sign_out' | |
118 | - end | |
119 | - | |
120 | - end | |
121 | - end | |
122 | -end | |
123 | - | |
124 | 5 | class MyApplication < Sinatra::Base |
125 | 6 | use Rack::Session::Cookie, secret: '123' |
126 | 7 | |
127 | 8 | STRATEGY = 'RemoteUser' |
128 | - use OmniAuth::Strategies::RemoteUser | |
9 | + #use OmniAuth::Strategies::RemoteUser | |
129 | 10 | #STRATEGY = 'developer' |
130 | - #use OmniAuth::Strategies::Developer | |
11 | + use OmniAuth::Strategies::Developer | |
131 | 12 | |
132 | 13 | |
133 | 14 | get '/login' do | ... | ... |