forked from omniauth/omniauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.rb
44 lines (37 loc) · 1.31 KB
/
password.rb
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
require 'digest/sha1'
module OmniAuth
module Strategies
class Password
include OmniAuth::Strategy
def initialize(app, secret = 'changethisappsecret', options = {})
@options = options
@options[:identifier_key] ||= 'nickname'
@secret = secret
super(app, :password)
end
attr_reader :secret
def request_phase
return fail!(:missing_information) unless request[:identifier] && request[:password]
return fail!(:password_mismatch) if request[:password_confirmation] && request[:password_confirmation] != '' && request[:password] != request[:password_confirmation]
env['REQUEST_METHOD'] = 'GET'
env['PATH_INFO'] = request.path + '/callback'
request['auth'] = auth_hash(encrypt(request[:identifier], request[:password]))
@app.call(env)
end
def auth_hash(crypted_password)
OmniAuth::Utils.deep_merge(super(), {
'uid' => crypted_password,
'user_info' => {
@options[:identifier_key] => request[:identifier]
}
})
end
def callback_phase
@app.call(env)
end
def encrypt(identifier, password)
Digest::SHA1.hexdigest([identifier, password, secret].join('::'))
end
end
end
end