devise_rpx_connectable 0.1.3 → 0.2.0
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/README.textile +18 -48
- data/Rakefile +1 -1
- data/lib/devise_rpx_connectable/model.rb +26 -22
- data/lib/devise_rpx_connectable/schema.rb +1 -1
- data/lib/devise_rpx_connectable/strategy.rb +15 -20
- data/lib/devise_rpx_connectable/version.rb +2 -1
- data/lib/devise_rpx_connectable/view_helpers.rb +2 -2
- data/lib/devise_rpx_connectable.rb +2 -0
- metadata +38 -14
data/README.textile
CHANGED
@@ -8,63 +8,31 @@ A great authentication gem for Rails applications.
|
|
8
8
|
|
9
9
|
"http://github.com/plataformatec/devise":http://github.com/plataformatec/devise
|
10
10
|
|
11
|
-
h2. What is RPX?
|
11
|
+
h2. What is RPX (now Janrain Engage)?
|
12
12
|
|
13
|
-
RPX is a Software as a Service (SaaS) that helps you manage multiple authentication methods (FacebookConnect, Google, Twitter, OpenID, MySpace...) using a single API.
|
13
|
+
RPX (now called Janrain Engage) is a Software as a Service (SaaS) that helps you manage multiple authentication methods (FacebookConnect, Google, Twitter, OpenID, MySpace...) using a single API.
|
14
14
|
It also provides a multilingual connection widget.
|
15
15
|
Instead of managing multiple authentication providers and APIs, you just need to handle one.
|
16
16
|
|
17
|
-
|
17
|
+
Janrain Engage provides free and paid accounts.
|
18
18
|
|
19
|
-
See *"
|
19
|
+
See *"Janrain Engage official homepage":https://rpxnow.com/*. If you want to see what it looks like, you may signup on the Janrain Engage website as it uses Engage for signup :).
|
20
20
|
|
21
21
|
h2. What is Devise RPX Connectable?
|
22
22
|
|
23
|
-
Devise RPX Connectable is a gem to integrate
|
23
|
+
Devise RPX Connectable is a gem to integrate Janrain Engage authentication in a Rails application using Devise.
|
24
24
|
|
25
|
-
Please note that this is an unofficial library. It is neither affiliated with, nor endorsed by
|
25
|
+
Please note that this is an unofficial library. It is neither affiliated with, nor endorsed by Janrain Inc.
|
26
26
|
|
27
27
|
h2. Dependencies
|
28
28
|
|
29
|
-
Devise RPX Connectable
|
29
|
+
Devise RPX Connectable should be compatible with the latest Rails and Devise versions (currently Rails 3.0 and Devise 1.2).
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
*Rails* : version 2.3.5
|
34
|
-
*Devise* : version 1.0.6
|
35
|
-
|
36
|
-
I also want it to be compatible with latest prerelease gems of Devise, Rails and Mongoid.
|
37
|
-
Therefore I also tested it with :
|
38
|
-
|
39
|
-
*Rails* : version 3.0.0beta3
|
40
|
-
*Mongoid* : version 2.0.0beta4
|
41
|
-
*Devise* : master branch.
|
31
|
+
IMPORTANT : This gem is now ONLY COMPATIBLE with Rails 3, if you want to use it with Rails 2, please use version 0.1.3.
|
42
32
|
|
43
33
|
h2. Installation
|
44
34
|
|
45
|
-
|
46
|
-
|
47
|
-
<pre>
|
48
|
-
$ sudo gem install devise_rpx_connectable
|
49
|
-
</pre>
|
50
|
-
|
51
|
-
...and in @config/environment.rb@:
|
52
|
-
|
53
|
-
<pre>
|
54
|
-
config.gem 'devise'
|
55
|
-
config.gem 'rpx_now'
|
56
|
-
config.gem 'devise_rpx_connectable'
|
57
|
-
</pre>
|
58
|
-
|
59
|
-
*Gem (Rails >= 3.0.0beta3)*
|
60
|
-
|
61
|
-
@Gemfile@
|
62
|
-
|
63
|
-
<pre>
|
64
|
-
gem 'devise', :git => 'git://github.com/plataformatec/devise.git'
|
65
|
-
gem 'rpx_now'
|
66
|
-
gem 'devise_rpx_connectable'
|
67
|
-
</pre>
|
35
|
+
As usual... Add @gem "devise_rpx_connectable"@ in your Gemfile.lock...
|
68
36
|
|
69
37
|
h2. Setup
|
70
38
|
|
@@ -93,19 +61,18 @@ In the Devise initializer (may be @config/initializers/devise.rb@) :
|
|
93
61
|
|
94
62
|
*RPXNow:API Key*
|
95
63
|
|
96
|
-
In @config/
|
64
|
+
In @config/application.rb@ or @config/environments/YOUR_ENV.rb@ (to set a different key for each environment...) :
|
97
65
|
|
98
66
|
<pre>
|
99
67
|
...
|
100
|
-
config.after_initialize do # so rake gems:install works
|
101
68
|
RPXNow.api_key = "aaaabbbbbccccdddddeeeeefffff"
|
102
|
-
end
|
103
69
|
...
|
104
70
|
</pre>
|
105
71
|
|
106
72
|
*Migrations*
|
107
73
|
|
108
74
|
Your model needs one attribute/column to store the RPX identifier. By default, this identifier is @rpx_identifier@.
|
75
|
+
So don't forget to add that field to your model (using a migration or whatever...).
|
109
76
|
|
110
77
|
*Views*
|
111
78
|
|
@@ -152,21 +119,22 @@ There is some advanced features that you may use...
|
|
152
119
|
|
153
120
|
*Devise:Model*
|
154
121
|
|
155
|
-
|
122
|
+
There are two hooks that you may define in your model : @before_rpx_success@ (called before each successful connection) and @before_rpx_auto_create@ (called only once before the auto saving of the user instance, when rpx_auto_create_account is enabled).
|
123
|
+
You get in parameter the RPX User object from the RPXNow gem which is basically a Hash containing more or less information depending on your RPX configuration and account.
|
124
|
+
Read the RPXNow gem documentation for more information about this...
|
156
125
|
|
157
126
|
<pre>
|
158
|
-
def
|
127
|
+
def before_rpx_success(rpx_user)
|
159
128
|
# Do something with rpx_user...
|
160
129
|
end
|
161
130
|
|
162
|
-
def
|
131
|
+
def before_rpx_auto_create(rpx_user)
|
163
132
|
# Do something with rpx_user
|
164
133
|
end
|
165
134
|
</pre>
|
166
135
|
|
167
136
|
h2. TODO
|
168
137
|
|
169
|
-
* With Rails 3 (only) I get an invalid auth token in sessions#create action. I have to skip the validation of the auth token. See why?
|
170
138
|
* Handle RPX multiple accounts mapping?
|
171
139
|
|
172
140
|
h2. Contributors
|
@@ -175,6 +143,8 @@ h2. Contributors
|
|
175
143
|
* "DohMoose":http://github.com/DohMoose
|
176
144
|
* "Chris de Bruin":http://github.com/chrisdebruin
|
177
145
|
* "Michael Bumann":http://github.com/bumi
|
146
|
+
* "Arek Flinik":http://github.com/blax
|
147
|
+
* "Nader Akhnoukh":http://github.com/iamnader
|
178
148
|
|
179
149
|
h2. Thanks
|
180
150
|
|
data/Rakefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'devise/models'
|
3
2
|
|
4
3
|
module Devise #:nodoc:
|
5
4
|
# module RpxConnectable #:nodoc:
|
@@ -56,16 +55,16 @@ module Devise #:nodoc:
|
|
56
55
|
end
|
57
56
|
alias :is_rpx_connected? :rpx_connected?
|
58
57
|
|
59
|
-
# Hook that gets called
|
60
|
-
# fetching additional user info (etc.) from RPX.
|
58
|
+
# Hook that gets called before a successful connection (each time).
|
59
|
+
# Useful for fetching additional user info (etc.) from RPX.
|
61
60
|
#
|
62
61
|
# Default: Do nothing.
|
63
62
|
#
|
64
|
-
# ==
|
63
|
+
# == Example:
|
65
64
|
#
|
66
65
|
# # Overridden in RPX connectable model, e.g. "User".
|
67
66
|
# #
|
68
|
-
# def
|
67
|
+
# def before_rpx_success(rpx_user)
|
69
68
|
#
|
70
69
|
# # Get email (if the provider supports it)
|
71
70
|
# email = rpx_user["email"]
|
@@ -77,14 +76,13 @@ module Devise #:nodoc:
|
|
77
76
|
#
|
78
77
|
# * http://github.com/grosser/rpx_now
|
79
78
|
#
|
80
|
-
def
|
81
|
-
if self.respond_to?(:
|
82
|
-
self.send(:before_rpx_connect, rpx_user) rescue nil
|
83
|
-
end
|
79
|
+
def on_before_rpx_success(rpx_user)
|
80
|
+
self.send(:before_rpx_success, rpx_user) if self.respond_to?(:before_rpx_success)
|
84
81
|
end
|
85
|
-
|
86
|
-
# Hook that gets called
|
87
|
-
#
|
82
|
+
|
83
|
+
# Hook that gets called before the auto creation of the user.
|
84
|
+
# Therefore, this hook is only called when rpx_auto_create_account config option is enabled.
|
85
|
+
# Useful for fetching additional user info (etc.) from RPX.
|
88
86
|
#
|
89
87
|
# Default: Do nothing.
|
90
88
|
#
|
@@ -92,14 +90,20 @@ module Devise #:nodoc:
|
|
92
90
|
#
|
93
91
|
# # Overridden in RPX connectable model, e.g. "User".
|
94
92
|
# #
|
95
|
-
# def
|
96
|
-
#
|
93
|
+
# def before_rpx_auto_create(rpx_user)
|
94
|
+
#
|
95
|
+
# # Get email (if the provider supports it)
|
96
|
+
# email = rpx_user["email"]
|
97
|
+
# # etc...
|
98
|
+
#
|
97
99
|
# end
|
98
100
|
#
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
# == For more info:
|
102
|
+
#
|
103
|
+
# * http://github.com/grosser/rpx_now
|
104
|
+
#
|
105
|
+
def on_before_rpx_auto_create(rpx_user)
|
106
|
+
self.send(:before_rpx_auto_create, rpx_user) if self.respond_to?(:before_rpx_auto_create)
|
103
107
|
end
|
104
108
|
|
105
109
|
module ClassMethods
|
@@ -115,10 +119,10 @@ module Devise #:nodoc:
|
|
115
119
|
# end
|
116
120
|
#
|
117
121
|
::Devise::Models.config(self,
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
+
:rpx_identifier_field,
|
123
|
+
:rpx_auto_create_account,
|
124
|
+
:rpx_extended_user_data,
|
125
|
+
:rpx_additional_user_data
|
122
126
|
)
|
123
127
|
|
124
128
|
# Alias don't work for some reason, so...a more Ruby-ish alias
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'devise/strategies/base'
|
3
2
|
|
4
3
|
module Devise #:nodoc:
|
5
4
|
module RpxConnectable #:nodoc:
|
@@ -24,26 +23,23 @@ module Devise #:nodoc:
|
|
24
23
|
fail!(:rpx_invalid) and return unless rpx_user
|
25
24
|
|
26
25
|
if user = klass.authenticate_with_rpx(:identifier => rpx_user["identifier"])
|
26
|
+
user.on_before_rpx_success(rpx_user)
|
27
27
|
success!(user)
|
28
|
-
|
29
|
-
if klass.rpx_auto_create_account?
|
30
|
-
user = returning(klass.new) do |u|
|
31
|
-
u.store_rpx_credentials!(rpx_user)
|
32
|
-
u.on_before_rpx_connect(rpx_user)
|
33
|
-
end
|
34
|
-
begin
|
35
|
-
user.save(false)
|
36
|
-
user.on_after_rpx_connect(rpx_user)
|
37
|
-
success!(user)
|
38
|
-
rescue
|
39
|
-
fail!(:rpx_invalid)
|
40
|
-
end
|
41
|
-
else
|
42
|
-
fail!(:rpx_invalid)
|
43
|
-
end
|
28
|
+
return
|
44
29
|
end
|
45
|
-
|
46
|
-
fail!(
|
30
|
+
|
31
|
+
fail!(:rpx_invalid) and return unless klass.rpx_auto_create_account?
|
32
|
+
|
33
|
+
user = klass.new
|
34
|
+
user.store_rpx_credentials!(rpx_user)
|
35
|
+
user.on_before_rpx_auto_create(rpx_user)
|
36
|
+
|
37
|
+
user.save(:validate => false)
|
38
|
+
user.on_before_rpx_success(rpx_user)
|
39
|
+
success!(user)
|
40
|
+
|
41
|
+
rescue
|
42
|
+
fail!(:rpx_invalid)
|
47
43
|
end
|
48
44
|
end
|
49
45
|
|
@@ -61,4 +57,3 @@ module Devise #:nodoc:
|
|
61
57
|
end
|
62
58
|
end
|
63
59
|
|
64
|
-
Warden::Strategies.add(:rpx_connectable, Devise::RpxConnectable::Strategies::RpxConnectable)
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'devise/mapping'
|
3
2
|
|
4
3
|
module Devise #:nodoc:
|
5
4
|
module RpxConnectable #:nodoc:
|
@@ -60,7 +59,8 @@ module Devise #:nodoc:
|
|
60
59
|
end
|
61
60
|
|
62
61
|
def build_token_url(return_url)
|
63
|
-
|
62
|
+
token = return_url.include?("?") ? "&" : "?"
|
63
|
+
"#{return_url}#{token}authenticity_token=#{Rack::Utils.escape(form_authenticity_token)}"
|
64
64
|
end
|
65
65
|
|
66
66
|
end
|
@@ -4,6 +4,8 @@ require 'rpx_now'
|
|
4
4
|
|
5
5
|
require 'devise_rpx_connectable/model'
|
6
6
|
require 'devise_rpx_connectable/strategy'
|
7
|
+
Warden::Strategies.add(:rpx_connectable, Devise::RpxConnectable::Strategies::RpxConnectable)
|
8
|
+
|
7
9
|
require 'devise_rpx_connectable/schema'
|
8
10
|
require 'devise_rpx_connectable/view_helpers'
|
9
11
|
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_rpx_connectable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Nicolas Blanco
|
@@ -9,29 +15,41 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-09-13 00:00:00 +02:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: devise
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
29
|
+
hash: 31
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 0
|
34
|
+
version: 1.2.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: rpx_now
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 33
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 6
|
49
|
+
- 19
|
33
50
|
version: 0.6.19
|
34
|
-
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
35
53
|
description: Devise << RPX
|
36
54
|
email: slainer68@gmail.com
|
37
55
|
executables: []
|
@@ -62,21 +80,27 @@ rdoc_options:
|
|
62
80
|
require_paths:
|
63
81
|
- lib
|
64
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
65
84
|
requirements:
|
66
85
|
- - ">="
|
67
86
|
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
68
90
|
version: "0"
|
69
|
-
version:
|
70
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
71
93
|
requirements:
|
72
94
|
- - ">="
|
73
95
|
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
74
99
|
version: "0"
|
75
|
-
version:
|
76
100
|
requirements: []
|
77
101
|
|
78
102
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.3.
|
103
|
+
rubygems_version: 1.3.7
|
80
104
|
signing_key:
|
81
105
|
specification_version: 3
|
82
106
|
summary: Devise << RPX
|