open_id_authentication 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/open_id_authentication/version.rb +2 -2
- data/lib/open_id_authentication.rb +63 -46
- metadata +19 -4
@@ -37,6 +37,21 @@ module OpenIdAuthentication
|
|
37
37
|
|
38
38
|
self.store = nil
|
39
39
|
|
40
|
+
if Rails.version >= '3'
|
41
|
+
class Railtie < ::Rails::Railtie
|
42
|
+
config.app_middleware.use OpenIdAuthentication
|
43
|
+
|
44
|
+
config.after_initialize do
|
45
|
+
OpenID::Util.logger = Rails.logger
|
46
|
+
end
|
47
|
+
|
48
|
+
ActiveSupport.on_load :action_controller do
|
49
|
+
ActionController::Base.send :include, ControllerMethods
|
50
|
+
#ActionController::Base.extend ControllerMethods
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
40
55
|
class Result
|
41
56
|
ERROR_MESSAGES = {
|
42
57
|
:missing => "Sorry, the OpenID server couldn't be found",
|
@@ -73,57 +88,59 @@ module OpenIdAuthentication
|
|
73
88
|
end
|
74
89
|
end
|
75
90
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
identifier
|
83
|
-
|
84
|
-
|
91
|
+
module ControllerMethods
|
92
|
+
protected
|
93
|
+
# The parameter name of "openid_identifier" is used rather than
|
94
|
+
# the Rails convention "open_id_identifier" because that's what
|
95
|
+
# the specification dictates in order to get browser auto-complete
|
96
|
+
# working across sites
|
97
|
+
def using_open_id?(identifier = nil) #:doc:
|
98
|
+
identifier ||= open_id_identifier
|
99
|
+
!identifier.blank? || request.env[Rack::OpenID::RESPONSE]
|
100
|
+
end
|
85
101
|
|
86
|
-
|
87
|
-
|
102
|
+
def authenticate_with_open_id(identifier = nil, options = {}, &block) #:doc:
|
103
|
+
identifier ||= open_id_identifier
|
88
104
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
105
|
+
if request.env[Rack::OpenID::RESPONSE]
|
106
|
+
complete_open_id_authentication(&block)
|
107
|
+
else
|
108
|
+
begin_open_id_authentication(identifier, options, &block)
|
109
|
+
end
|
93
110
|
end
|
94
|
-
end
|
95
111
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
112
|
+
private
|
113
|
+
def open_id_identifier
|
114
|
+
params[:openid_identifier] || params[:openid_url]
|
115
|
+
end
|
100
116
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
117
|
+
def begin_open_id_authentication(identifier, options = {})
|
118
|
+
options[:identifier] = identifier
|
119
|
+
value = Rack::OpenID.build_header(options)
|
120
|
+
response.headers[Rack::OpenID::AUTHENTICATE_HEADER] = value
|
121
|
+
head :unauthorized
|
122
|
+
end
|
107
123
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
def complete_open_id_authentication
|
125
|
+
response = request.env[Rack::OpenID::RESPONSE]
|
126
|
+
identifier = response.display_identifier
|
127
|
+
|
128
|
+
case response.status
|
129
|
+
when OpenID::Consumer::SUCCESS
|
130
|
+
yield Result[:successful], identifier,
|
131
|
+
OpenID::SReg::Response.from_success_response(response),
|
132
|
+
OpenID::AX::FetchResponse.from_success_response(response)
|
133
|
+
when :missing
|
134
|
+
yield Result[:missing], identifier, nil
|
135
|
+
when :invalid
|
136
|
+
yield Result[:invalid], identifier, nil
|
137
|
+
when OpenID::Consumer::CANCEL
|
138
|
+
yield Result[:canceled], identifier, nil
|
139
|
+
when OpenID::Consumer::FAILURE
|
140
|
+
yield Result[:failed], identifier, nil
|
141
|
+
when OpenID::Consumer::SETUP_NEEDED
|
142
|
+
yield Result[:setup_needed], response.setup_url, nil
|
143
|
+
end
|
127
144
|
end
|
128
|
-
|
145
|
+
end
|
129
146
|
end
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_id_authentication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Patrick Robertson
|
@@ -10,7 +15,7 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
18
|
+
date: 2011-09-18 00:00:00 -04:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
@@ -21,6 +26,10 @@ dependencies:
|
|
21
26
|
requirements:
|
22
27
|
- - ~>
|
23
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
24
33
|
version: "1.3"
|
25
34
|
type: :runtime
|
26
35
|
version_requirements: *id001
|
@@ -54,17 +63,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
63
|
requirements:
|
55
64
|
- - ">="
|
56
65
|
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
57
69
|
version: "0"
|
58
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
71
|
none: false
|
60
72
|
requirements:
|
61
73
|
- - ">="
|
62
74
|
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
63
78
|
version: "0"
|
64
79
|
requirements: []
|
65
80
|
|
66
81
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.3.7
|
68
83
|
signing_key:
|
69
84
|
specification_version: 3
|
70
85
|
summary: open_id_authentication provides a thin wrapper around the excellent rack-openid gem.
|