omniauth-focovirtual 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/omniauth-focovirtual/version.rb +1 -1
- data/lib/omniauth-focovirtual.rb +46 -3
- metadata +1 -1
data/lib/omniauth-focovirtual.rb
CHANGED
@@ -1,7 +1,50 @@
|
|
1
1
|
require "omniauth-focovirtual/version"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require 'omniauth/core'
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class FocoLogin
|
7
|
+
include OmniAuth::Strategy
|
8
|
+
|
9
|
+
# receive parameters from the strategy declaration and save them
|
10
|
+
def initialize(app, secret, auth_redirect, options = {})
|
11
|
+
@secret = secret
|
12
|
+
@auth_redirect = auth_redirect
|
13
|
+
super(app, :foco_login, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# redirect to the Pixelation website
|
17
|
+
def request_phase
|
18
|
+
r = Rack::Response.new
|
19
|
+
r.redirect @auth_redirect
|
20
|
+
r.finish
|
21
|
+
end
|
22
|
+
|
23
|
+
def callback_phase
|
24
|
+
uid, username, token = request.params["uid"], request.params["name"], request.params["token"]
|
25
|
+
sha1 = Digest::SHA1.hexdigest("a mix of #{@secret}, #{uid}, #{name}")
|
26
|
+
|
27
|
+
# check if the request comes from Pixelation or not
|
28
|
+
if sha1 == token
|
29
|
+
@uid, @username = uid, username
|
30
|
+
# OmniAuth takes care of the rest
|
31
|
+
super
|
32
|
+
else
|
33
|
+
# OmniAuth takes care of the rest
|
34
|
+
fail!(:invalid_credentials)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# normalize user's data according to http://github.com/intridea/omniauth/wiki/Auth-Hash-Schema
|
39
|
+
def auth_hash
|
40
|
+
OmniAuth::Utils.deep_merge(super(), {
|
41
|
+
'uid' => @uid,
|
42
|
+
'user_info' => {
|
43
|
+
'name' => @username,
|
44
|
+
'nickname' => @username
|
45
|
+
}
|
46
|
+
})
|
47
|
+
end
|
48
|
+
end
|
6
49
|
end
|
7
50
|
end
|