Commit ae5b9fcb00887bd2d7e33ca881ea4fec35785ee5
1 parent
c8d60a16
Exists in
master
and in
2 other branches
Initial version of remote_user strategy
Showing
3 changed files
with
22 additions
and
13 deletions
Show diff stats
lib/omniauth/remote_user.rb
1 | -require 'omniauth' | 1 | +require 'omniauth/core' |
2 | 2 | ||
3 | module Omniauth | 3 | module Omniauth |
4 | module Stratagies | 4 | module Stratagies |
5 | autoload :RemoteUser, 'omniauth/stratagies/remote_user' | 5 | autoload :RemoteUser, 'omniauth/stratagies/remote_user' |
6 | end | 6 | end |
7 | - | ||
8 | - module Remote_user | ||
9 | - autoload :Model, 'omniauth/remote_user/model' | ||
10 | - module Models | ||
11 | - autoload :ActiveRecord, 'omniauth/remote_user/models/active_record' | ||
12 | - end | ||
13 | end | 7 | end |
14 | 8 |
lib/omniauth/strategies/remote_user.rb
@@ -3,16 +3,31 @@ module OmniAuth | @@ -3,16 +3,31 @@ module OmniAuth | ||
3 | class RemoteUser | 3 | class RemoteUser |
4 | include OmniAuth::Strategy | 4 | include OmniAuth::Strategy |
5 | 5 | ||
6 | - option :fields, [:name, :email] | ||
7 | - option :uid_field, :name | 6 | + def validate_remote_user |
7 | + if !env['HTTP_REMOTE_USER'].blank? | ||
8 | + env['HTTP_REMOTE_USER'] | ||
9 | + else | ||
10 | + env['HTTP_X_FORWARDED_USER'] | ||
11 | + end | ||
12 | + end | ||
8 | 13 | ||
9 | def request_phase | 14 | def request_phase |
15 | + @uid = validate_remote_user | ||
16 | + return fail!(:no_remote_user) unless @uid | ||
10 | 17 | ||
11 | - end | 18 | + @user_data[:name] = @uid['NAME'] |
19 | + @user_data[:email] = @uid['EMAIL'] | ||
12 | 20 | ||
13 | - def callback_phase | 21 | + @env['omniauth.auth'] = auth_hash |
22 | + @env['REQUEST_METHOD'] = 'GET' | ||
23 | + @env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback" | ||
14 | 24 | ||
25 | + call_app! | ||
15 | end | 26 | end |
27 | + | ||
28 | + uid { @uid['EMAIL'] } | ||
29 | + info{ @user_data } | ||
30 | + | ||
16 | end | 31 | end |
17 | end | 32 | end |
18 | end | 33 | end |
lib/omniauth_remote_user.rb