rpx_now 0.6.4 → 0.6.5
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.markdown +10 -2
- data/VERSION +1 -1
- data/lib/rpx_now.rb +39 -25
- data/lib/rpx_now/api.rb +12 -1
- data/rpx_now.gemspec +2 -2
- data/spec/rpx_now_spec.rb +41 -11
- metadata +2 -2
data/README.markdown
CHANGED
@@ -33,9 +33,15 @@ View
|
|
33
33
|
#'mywebsite' is your subdomain/realm on RPX
|
34
34
|
<%=RPXNow.embed_code('mywebsite',rpx_token_sessions_url)%>
|
35
35
|
OR
|
36
|
-
<%=RPXNow.popup_code('Login here...','mywebsite',rpx_token_sessions_url
|
36
|
+
<%=RPXNow.popup_code('Login here...', 'mywebsite', rpx_token_sessions_url, options)%>
|
37
37
|
|
38
|
-
|
38
|
+
Options
|
39
|
+
:language=>'en' # rpx tries to detect the users language, but you may overwrite it [possible languages](https://rpxnow.com/docs#sign-in_localization)
|
40
|
+
:default_provider=>'google' # [possible default providers](https://rpxnow.com/docs#sign-in_default_provider)
|
41
|
+
:flags=>'show_provider_list' # [possible flags](https://rpxnow.com/docs#sign-in_interface)
|
42
|
+
|
43
|
+
`popup_code` can also be called with `:unobstrusive=>true`, to still get a nice popup include `RPXNow.popup_source('mywebsite',rpx_token_sessions_url, [options])` somewhere else.
|
44
|
+
Options like :language / :flags should be given for both.
|
39
45
|
|
40
46
|
Environment
|
41
47
|
-----------
|
@@ -50,6 +56,8 @@ Environment
|
|
50
56
|
|
51
57
|
Controller
|
52
58
|
----------
|
59
|
+
skip_before_filter :verify_authenticity_token, :only => [:rpx_token] # RPX does not pass Rails form tokens...
|
60
|
+
|
53
61
|
# user_data
|
54
62
|
# found: {:name=>'John Doe', :username => 'john', :email=>'john@doe.com', :identifier=>'blug.google.com/openid/dsdfsdfs3f3'}
|
55
63
|
# not found: nil (can happen with e.g. invalid tokens)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.5
|
data/lib/rpx_now.rb
CHANGED
@@ -64,18 +64,20 @@ module RPXNow
|
|
64
64
|
end
|
65
65
|
alias get_contacts contacts
|
66
66
|
|
67
|
-
|
68
|
-
|
67
|
+
# iframe for rpx login
|
68
|
+
# options: :width, :height, :language, :flags
|
69
|
+
def embed_code(subdomain, url, options={})
|
70
|
+
options = {:width => '400', :height => '240'}.merge(options)
|
69
71
|
<<-EOF
|
70
|
-
<iframe src="
|
72
|
+
<iframe src="#{Api.host(subdomain)}/openid/embed?#{embed_params(url, options)}"
|
71
73
|
scrolling="no" frameBorder="no" style="width:#{options[:width]}px;height:#{options[:height]}px;">
|
72
74
|
</iframe>
|
73
75
|
EOF
|
74
76
|
end
|
75
77
|
|
78
|
+
# popup window for rpx login
|
79
|
+
# options: :language / :flags / :unobtrusive
|
76
80
|
def popup_code(text, subdomain, url, options = {})
|
77
|
-
options = options.dup
|
78
|
-
options[:language] ||= 'en'
|
79
81
|
if options[:unobtrusive]
|
80
82
|
unobtrusive_popup_code(text, subdomain, url, options)
|
81
83
|
else
|
@@ -83,12 +85,39 @@ module RPXNow
|
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
86
|
-
|
87
|
-
|
88
|
+
# javascript for popup
|
89
|
+
# only needed in combination with popup_code(x,y,z, :unobtrusive => true)
|
90
|
+
def popup_source(subdomain, url, options={})
|
91
|
+
<<-EOF
|
92
|
+
<script src="#{Api.host}/openid/v#{extract_version(options)}/widget" type="text/javascript"></script>
|
93
|
+
<script type="text/javascript">
|
94
|
+
//<![CDATA[
|
95
|
+
RPXNOW.token_url = '#{url}';
|
96
|
+
RPXNOW.realm = '#{subdomain}';
|
97
|
+
RPXNOW.overlay = true;
|
98
|
+
#{ "RPXNOW.language_preference = '#{options[:language]}';" if options[:language] }
|
99
|
+
#{ "RPXNOW.default_provider = '#{options[:default_provider]}';" if options[:default_provider] }
|
100
|
+
#{ "RPXNOW.flags = '#{options[:flags]}';" if options[:flags] }
|
101
|
+
//]]>
|
102
|
+
</script>
|
103
|
+
EOF
|
104
|
+
end
|
105
|
+
|
106
|
+
def extract_version(options)
|
107
|
+
options[:api_version] || api_version
|
88
108
|
end
|
89
109
|
|
90
110
|
private
|
91
111
|
|
112
|
+
def self.embed_params(url, options)
|
113
|
+
{
|
114
|
+
:token_url => url,
|
115
|
+
:language_preference => options[:language],
|
116
|
+
:flags => options[:flags],
|
117
|
+
:default_provider => options[:default_provider]
|
118
|
+
}.map{|k,v| "#{k}=#{v}" if v}.compact.join('&')
|
119
|
+
end
|
120
|
+
|
92
121
|
def self.parse_user_data(response)
|
93
122
|
user_data = response['profile']
|
94
123
|
data = {}
|
@@ -101,27 +130,12 @@ module RPXNow
|
|
101
130
|
end
|
102
131
|
|
103
132
|
def unobtrusive_popup_code(text, subdomain, url, options={})
|
104
|
-
|
105
|
-
%Q(<a class="rpxnow" href="https://#{subdomain}.#{Api::HOST}/openid/v#{version}/signin?token_url=#{url}&language_preference=#{options[:language]}">#{text}</a>)
|
133
|
+
%Q(<a class="rpxnow" href="#{Api.host(subdomain)}/openid/v#{extract_version(options)}/signin?#{embed_params(url, options)}">#{text}</a>)
|
106
134
|
end
|
107
135
|
|
108
136
|
def obtrusive_popup_code(text, subdomain, url, options = {})
|
109
|
-
|
110
|
-
|
111
|
-
<a class="rpxnow" onclick="return false;" href="https://#{subdomain}.#{Api::HOST}/openid/v#{version}/signin?token_url=#{url}">
|
112
|
-
#{text}
|
113
|
-
</a>
|
114
|
-
<script src="https://#{Api::HOST}/openid/v#{version}/widget" type="text/javascript"></script>
|
115
|
-
<script type="text/javascript">
|
116
|
-
//<![CDATA[
|
117
|
-
RPXNOW.token_url = "#{url}";
|
118
|
-
|
119
|
-
RPXNOW.realm = "#{subdomain}";
|
120
|
-
RPXNOW.overlay = true;
|
121
|
-
RPXNOW.language_preference = '#{options[:language]}';
|
122
|
-
//]]>
|
123
|
-
</script>
|
124
|
-
EOF
|
137
|
+
unobtrusive_popup_code(text, subdomain, url, options) +
|
138
|
+
popup_source(subdomain, url, options)
|
125
139
|
end
|
126
140
|
|
127
141
|
class ServerError < RuntimeError; end #backwards compatibility / catch all
|
data/lib/rpx_now/api.rb
CHANGED
@@ -8,12 +8,23 @@ module RPXNow
|
|
8
8
|
SSL_CERT = File.join(File.dirname(__FILE__), '..', '..', 'certs', 'ssl_cert.pem')
|
9
9
|
|
10
10
|
def self.call(method, data)
|
11
|
-
|
11
|
+
data = data.dup
|
12
|
+
version = RPXNow.extract_version(data)
|
13
|
+
data.delete(:api_version)
|
14
|
+
|
12
15
|
path = "/api/v#{version}/#{method}"
|
13
16
|
response = request(path, {:apiKey => RPXNow.api_key}.merge(data))
|
14
17
|
parse_response(response)
|
15
18
|
end
|
16
19
|
|
20
|
+
def self.host(subdomain=nil)
|
21
|
+
if subdomain
|
22
|
+
"https://#{subdomain}.#{Api::HOST}"
|
23
|
+
else
|
24
|
+
"https://#{Api::HOST}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
17
28
|
private
|
18
29
|
|
19
30
|
def self.request(path, data)
|
data/rpx_now.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rpx_now}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-11}
|
13
13
|
s.email = %q{grosser.michael@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.markdown"
|
data/spec/rpx_now_spec.rb
CHANGED
@@ -76,10 +76,10 @@ describe RPXNow do
|
|
76
76
|
RPXNow.embed_code('xxx','my_url').should =~ /token_url=my_url/
|
77
77
|
end
|
78
78
|
|
79
|
-
it "defaults to
|
80
|
-
RPXNow.embed_code('xxx', 'my_url').
|
79
|
+
it "defaults to no language" do
|
80
|
+
RPXNow.embed_code('xxx', 'my_url').should_not =~ /language_preference/
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
it "has a changeable language" do
|
84
84
|
RPXNow.embed_code('xxx', 'my_url', :language => 'es').should =~ /language_preference=es/
|
85
85
|
end
|
@@ -114,9 +114,9 @@ describe RPXNow do
|
|
114
114
|
|
115
115
|
describe 'unobstrusive' do
|
116
116
|
it "can build an unobtrusive widget" do
|
117
|
-
expected = %Q(<a class="rpxnow" href="https://subdomain.rpxnow.com/openid/v2/signin?token_url=http://fake.domain.com
|
117
|
+
expected = %Q(<a class="rpxnow" href="https://subdomain.rpxnow.com/openid/v2/signin?token_url=http://fake.domain.com/">sign on</a>)
|
118
118
|
actual = RPXNow.popup_code('sign on', 'subdomain', 'http://fake.domain.com/', :unobtrusive => true)
|
119
|
-
|
119
|
+
actual.should == expected
|
120
120
|
end
|
121
121
|
|
122
122
|
it "can change api version" do
|
@@ -124,7 +124,15 @@ describe RPXNow do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
it "can change language" do
|
127
|
-
RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :language => 'XX').should include("
|
127
|
+
RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :language => 'XX').should include("language_preference=XX")
|
128
|
+
end
|
129
|
+
|
130
|
+
it "can add flags" do
|
131
|
+
RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :flags => 'test').should include("flags=test")
|
132
|
+
end
|
133
|
+
|
134
|
+
it "can add default_provider" do
|
135
|
+
RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :default_provider => 'test').should include("default_provider=test")
|
128
136
|
end
|
129
137
|
end
|
130
138
|
|
@@ -136,12 +144,34 @@ describe RPXNow do
|
|
136
144
|
RPXNow.popup_code('x','y','z').should =~ %r(/openid/v2/signin)
|
137
145
|
end
|
138
146
|
|
139
|
-
|
140
|
-
|
147
|
+
describe 'language' do
|
148
|
+
it "defaults to no language" do
|
149
|
+
RPXNow.popup_code('x','y','z').should_not =~ /RPXNOW.language_preference/
|
150
|
+
end
|
151
|
+
|
152
|
+
it "has a changeable language" do
|
153
|
+
RPXNow.popup_code('x','y','z', :language=>'de').should =~ /RPXNOW.language_preference = 'de'/
|
154
|
+
end
|
141
155
|
end
|
142
|
-
|
143
|
-
|
144
|
-
|
156
|
+
|
157
|
+
describe 'flags' do
|
158
|
+
it "defaults to no language" do
|
159
|
+
RPXNow.popup_code('x','y','z').should_not =~ /RPXNOW.flags/
|
160
|
+
end
|
161
|
+
|
162
|
+
it "can have flags" do
|
163
|
+
RPXNow.popup_code('x','y','z', :flags=>'test').should =~ /RPXNOW.flags = 'test'/
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe 'default_provider' do
|
168
|
+
it "defaults to no provider" do
|
169
|
+
RPXNow.popup_code('x','y','z').should_not =~ /RPXNOW.default_provider/
|
170
|
+
end
|
171
|
+
|
172
|
+
it "can have default_provider" do
|
173
|
+
RPXNow.popup_code('x','y','z', :default_provider=>'test').should =~ /RPXNOW.default_provider = 'test'/
|
174
|
+
end
|
145
175
|
end
|
146
176
|
end
|
147
177
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpx_now
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-11 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|