pixnet-sso 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/pixnet-sso/config.rb +3 -0
- data/lib/pixnet-sso/controller_methods.rb +32 -2
- data/lib/pixnet-sso/helper.rb +12 -0
- data/lib/pixnet-sso/openid_controller_methods.rb +16 -1
- metadata +74 -48
data/lib/pixnet-sso/config.rb
CHANGED
|
@@ -6,7 +6,11 @@ module Pixnet
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def current_user
|
|
9
|
-
|
|
9
|
+
if Pixnet::SSO::Config.version == 1
|
|
10
|
+
@current_user ||= login_from_session unless @current_user == false
|
|
11
|
+
else
|
|
12
|
+
@current_user ||= login_from_cookie unless @current_user == false
|
|
13
|
+
end
|
|
10
14
|
end
|
|
11
15
|
|
|
12
16
|
def current_user=(new_user)
|
|
@@ -18,6 +22,16 @@ module Pixnet
|
|
|
18
22
|
self.current_user = Pixnet::SSO::Config.user_klass.find(session[:user_id]) if session[:user_id]
|
|
19
23
|
end
|
|
20
24
|
|
|
25
|
+
def login_from_cookie
|
|
26
|
+
pixdata = get_login_user
|
|
27
|
+
if pixdata
|
|
28
|
+
sso = Pixnet::SSO::App.new
|
|
29
|
+
self.current_user = sso.get_user(pixdata['user_name'])
|
|
30
|
+
else
|
|
31
|
+
self.current_user = nil
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
21
35
|
def login_required
|
|
22
36
|
if logged_in?
|
|
23
37
|
return true
|
|
@@ -27,11 +41,27 @@ module Pixnet
|
|
|
27
41
|
end
|
|
28
42
|
end
|
|
29
43
|
|
|
44
|
+
# sso2
|
|
45
|
+
def get_login_user(type = 'pixnet')
|
|
46
|
+
pixdata = cookies['pixdata'] ? JSON::parse(cookies['pixdata']) : nil
|
|
47
|
+
if (!pixdata or !pixdata['sig'])
|
|
48
|
+
return nil
|
|
49
|
+
end
|
|
50
|
+
sig = pixdata['sig']
|
|
51
|
+
str = cookies['pixdata'].gsub(/,"sig":\d+/, '')
|
|
52
|
+
crc32 = Zlib.crc32("#{str}#{pixdata['nonce']}#{Pixnet::SSO::Config.sso_secret}")
|
|
53
|
+
return nil unless sig == crc32
|
|
54
|
+
return pixdata if 'pixnet' == type && pixdata['user_name']
|
|
55
|
+
return pixdata if 'openid' == type && pixdata['openid']
|
|
56
|
+
return nil
|
|
57
|
+
end
|
|
58
|
+
|
|
30
59
|
def self.included(base)
|
|
31
60
|
base.helper_method :logged_in?
|
|
32
61
|
base.helper_method :current_user
|
|
33
|
-
base.helper_method :login_required
|
|
62
|
+
base.helper_method :login_required #sso1
|
|
34
63
|
base.helper_method :redirect_back_or_default
|
|
64
|
+
base.helper_method :get_login_user
|
|
35
65
|
end
|
|
36
66
|
end
|
|
37
67
|
end
|
data/lib/pixnet-sso/helper.rb
CHANGED
|
@@ -35,6 +35,18 @@ module Pixnet
|
|
|
35
35
|
</script>
|
|
36
36
|
<script src="//api.pixnet.cc/api/checklogin.php?js=1&unique=#{unique}&timestamp=#{now}&type=2" type="text/javascript"></script>
|
|
37
37
|
<script src="http://s.pixfs.net/js/pixnet/checklogin.js?v=20110519" type="text/javascript"></script>
|
|
38
|
+
MSG
|
|
39
|
+
return html.html_safe
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def pixnet_sso2_scripts
|
|
43
|
+
unique = Zlib.crc32(UUID.generate).to_s
|
|
44
|
+
now = Time.now.to_i.to_s
|
|
45
|
+
sig = Zlib.crc32("#{Pixnet::SSO::Config.sso_secret}#{unique}#{now}")
|
|
46
|
+
html = <<MSG
|
|
47
|
+
<script type="text/javascript" src="//checklogin.#{request.host}/login_name.php?key=#{Pixnet::SSO::Config.sso_key}&unique=#{unique}×tamp=#{now}&sig=#{sig}"></script>
|
|
48
|
+
<script type="text/javascript" src="//api.pixnet.cc/api/checklogin.php?js=1&unique=#{unique}×tamp=#{now}&type=2"></script>
|
|
49
|
+
<script type="text/javascript" src="//s.pixfs.net/js/pixnet/checklogin.min.js"></script>
|
|
38
50
|
MSG
|
|
39
51
|
return html.html_safe
|
|
40
52
|
end
|
|
@@ -7,13 +7,28 @@ module Pixnet
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def current_openid_user
|
|
10
|
-
|
|
10
|
+
if Pixnet::SSO::Config.version == 1
|
|
11
|
+
@current_openid_user ||= openid_login_from_session unless @current_openid_user == false
|
|
12
|
+
else
|
|
13
|
+
@current_openid_user ||= openid_login_from_cookie unless @current_openid_user == false
|
|
14
|
+
end
|
|
11
15
|
end
|
|
12
16
|
|
|
13
17
|
def openid_login_from_session
|
|
14
18
|
self.current_openid_user = Pixnet::SSO::Config.openid_klass.find(session[:openid_user_id]) if session[:openid_user_id]
|
|
15
19
|
end
|
|
16
20
|
|
|
21
|
+
def openid_login_from_cookie
|
|
22
|
+
pixdata = get_login_user('openid')
|
|
23
|
+
if pixdata
|
|
24
|
+
sso = Pixnet::SSO::App.new
|
|
25
|
+
info = { 'msg' => pixdata }
|
|
26
|
+
self.current_openid_user = sso.get_openid_user(info)
|
|
27
|
+
else
|
|
28
|
+
self.current_openid_user = nil
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
17
32
|
def self.included(base)
|
|
18
33
|
base.helper_method :current_openid_user
|
|
19
34
|
end
|
metadata
CHANGED
|
@@ -1,56 +1,77 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pixnet-sso
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease:
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 4
|
|
10
|
+
version: 0.0.4
|
|
6
11
|
platform: ruby
|
|
7
|
-
authors:
|
|
12
|
+
authors:
|
|
8
13
|
- Manic Chuang
|
|
9
14
|
autorequire:
|
|
10
15
|
bindir: bin
|
|
11
16
|
cert_chain: []
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
|
|
18
|
+
date: 2012-04-09 00:00:00 +08:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies:
|
|
21
|
+
- !ruby/object:Gem::Dependency
|
|
22
|
+
prerelease: false
|
|
15
23
|
name: rails
|
|
16
|
-
|
|
24
|
+
type: :runtime
|
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
17
26
|
none: false
|
|
18
|
-
requirements:
|
|
19
|
-
- -
|
|
20
|
-
- !ruby/object:Gem::Version
|
|
27
|
+
requirements:
|
|
28
|
+
- - ">="
|
|
29
|
+
- !ruby/object:Gem::Version
|
|
30
|
+
hash: 7
|
|
31
|
+
segments:
|
|
32
|
+
- 3
|
|
33
|
+
- 0
|
|
34
|
+
- 0
|
|
21
35
|
version: 3.0.0
|
|
22
|
-
|
|
36
|
+
version_requirements: *id001
|
|
37
|
+
- !ruby/object:Gem::Dependency
|
|
23
38
|
prerelease: false
|
|
24
|
-
version_requirements: *14348620
|
|
25
|
-
- !ruby/object:Gem::Dependency
|
|
26
39
|
name: uuid
|
|
27
|
-
requirement: &14347920 !ruby/object:Gem::Requirement
|
|
28
|
-
none: false
|
|
29
|
-
requirements:
|
|
30
|
-
- - ! '>='
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0'
|
|
33
40
|
type: :runtime
|
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
hash: 3
|
|
47
|
+
segments:
|
|
48
|
+
- 0
|
|
49
|
+
version: "0"
|
|
50
|
+
version_requirements: *id002
|
|
51
|
+
- !ruby/object:Gem::Dependency
|
|
34
52
|
prerelease: false
|
|
35
|
-
version_requirements: *14347920
|
|
36
|
-
- !ruby/object:Gem::Dependency
|
|
37
53
|
name: json
|
|
38
|
-
requirement: &14347320 !ruby/object:Gem::Requirement
|
|
39
|
-
none: false
|
|
40
|
-
requirements:
|
|
41
|
-
- - ! '>='
|
|
42
|
-
- !ruby/object:Gem::Version
|
|
43
|
-
version: '0'
|
|
44
54
|
type: :runtime
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
56
|
+
none: false
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
hash: 3
|
|
61
|
+
segments:
|
|
62
|
+
- 0
|
|
63
|
+
version: "0"
|
|
64
|
+
version_requirements: *id003
|
|
47
65
|
description: Client for PIXNET SSO
|
|
48
|
-
email:
|
|
66
|
+
email:
|
|
49
67
|
- manic@pixnet.tw
|
|
50
68
|
executables: []
|
|
69
|
+
|
|
51
70
|
extensions: []
|
|
71
|
+
|
|
52
72
|
extra_rdoc_files: []
|
|
53
|
-
|
|
73
|
+
|
|
74
|
+
files:
|
|
54
75
|
- app/controllers/pixauth_controller.rb
|
|
55
76
|
- config/routes.rb
|
|
56
77
|
- lib/tasks/pixnet-sso_tasks.rake
|
|
@@ -70,34 +91,39 @@ files:
|
|
|
70
91
|
- MIT-LICENSE
|
|
71
92
|
- Rakefile
|
|
72
93
|
- README.md
|
|
94
|
+
has_rdoc: true
|
|
73
95
|
homepage: https://github.com/manic/pixnet-sso
|
|
74
96
|
licenses: []
|
|
97
|
+
|
|
75
98
|
post_install_message:
|
|
76
99
|
rdoc_options: []
|
|
77
|
-
|
|
100
|
+
|
|
101
|
+
require_paths:
|
|
78
102
|
- lib
|
|
79
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
104
|
none: false
|
|
81
|
-
requirements:
|
|
82
|
-
- -
|
|
83
|
-
- !ruby/object:Gem::Version
|
|
84
|
-
|
|
85
|
-
segments:
|
|
105
|
+
requirements:
|
|
106
|
+
- - ">="
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
hash: 3
|
|
109
|
+
segments:
|
|
86
110
|
- 0
|
|
87
|
-
|
|
88
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
|
+
version: "0"
|
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
113
|
none: false
|
|
90
|
-
requirements:
|
|
91
|
-
- -
|
|
92
|
-
- !ruby/object:Gem::Version
|
|
93
|
-
|
|
94
|
-
segments:
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
hash: 3
|
|
118
|
+
segments:
|
|
95
119
|
- 0
|
|
96
|
-
|
|
120
|
+
version: "0"
|
|
97
121
|
requirements: []
|
|
122
|
+
|
|
98
123
|
rubyforge_project:
|
|
99
|
-
rubygems_version: 1.
|
|
124
|
+
rubygems_version: 1.5.2
|
|
100
125
|
signing_key:
|
|
101
126
|
specification_version: 3
|
|
102
127
|
summary: Client for PIXNET SSO
|
|
103
128
|
test_files: []
|
|
129
|
+
|