ruby-openid 2.1.8 → 2.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.
Potentially problematic release.
This version of ruby-openid might be problematic. Click here for more details.
- data/CHANGELOG.md +13 -0
- data/INSTALL.md +47 -0
- data/README.md +82 -0
- data/{UPGRADE → UPGRADE.md} +54 -55
- data/examples/active_record_openid_store/README +4 -2
- data/examples/active_record_openid_store/XXX_add_open_id_store_to_db.rb +1 -1
- data/examples/active_record_openid_store/lib/openid_ar_store.rb +1 -1
- data/examples/rails_openid/app/controllers/server_controller.rb +0 -6
- data/lib/openid.rb +2 -2
- data/lib/openid/consumer/responses.rb +2 -0
- data/lib/openid/dh.rb +1 -1
- data/lib/openid/extensions/ax.rb +44 -22
- data/lib/openid/extensions/ui.rb +53 -0
- data/lib/openid/message.rb +1 -1
- data/lib/openid/store/filesystem.rb +8 -9
- data/lib/openid/store/memcache.rb +10 -2
- data/lib/openid/trustroot.rb +1 -0
- data/lib/openid/util.rb +6 -0
- data/lib/openid/version.rb +3 -0
- data/test/data/trustroot.txt +2 -2
- data/test/test_accept.rb +1 -1
- data/test/test_associationmanager.rb +1 -1
- data/test/test_ax.rb +89 -19
- data/test/test_checkid_request.rb +1 -1
- data/test/test_consumer.rb +5 -2
- data/test/test_cryptutil.rb +1 -1
- data/test/test_dh.rb +1 -1
- data/test/test_discover.rb +2 -4
- data/test/test_discovery_manager.rb +1 -3
- data/test/test_extension.rb +2 -2
- data/test/test_fetchers.rb +3 -7
- data/test/test_filters.rb +25 -31
- data/test/test_idres.rb +17 -17
- data/test/test_kvpost.rb +2 -2
- data/test/test_message.rb +1 -2
- data/test/test_oauth.rb +3 -2
- data/test/test_openid_yadis.rb +0 -1
- data/test/test_pape.rb +7 -6
- data/test/test_parsehtml.rb +2 -2
- data/test/test_server.rb +17 -22
- data/test/test_sreg.rb +8 -8
- data/test/test_stores.rb +1 -2
- data/test/test_trustroot.rb +14 -15
- data/test/test_ui.rb +93 -0
- data/test/test_urinorm.rb +2 -3
- data/test/test_util.rb +2 -3
- data/test/test_xrds.rb +13 -15
- data/test/test_xrires.rb +27 -14
- data/test/test_yadis_discovery.rb +1 -3
- metadata +260 -189
- data/CHANGELOG +0 -215
- data/INSTALL +0 -47
- data/README +0 -81
- data/admin/runtests.rb +0 -45
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 2.2.0
|
4
|
+
|
5
|
+
* Bundler compatibility and bundler gem tasks - 72d551945f9577bf5d0e516c673c648791b0e795
|
6
|
+
* register_namespace_alias for AX message - aeaf050d21aeb681a220758f1cc61b9086f73152
|
7
|
+
* Fixed JRuby (1.9 mode) incompatibilty - 40baed6cf7326025058a131c2b76047345618539
|
8
|
+
* Added UI extension support - a276a63d68639e985c1f327cf817489ccc5f9a17
|
9
|
+
* Add attr_reader for setup_url on SetupNeededResponse - 75a7e98005542ede6db3fc7f1fc551e0a2ca044a
|
10
|
+
* Encode form inputs - c9e9b5b52f8a23df3159c2387b6330d5df40f35b
|
11
|
+
* Fixed cleanup AR associations whose expiry is past, not upcoming - 2265179a6d5c8b51ccc741180db46b618dd3caf9
|
12
|
+
* Fixed issue with Memcache store and Dalli - ef84bf73da9c99c67b0632252bf0349e2360cbc7
|
13
|
+
* Improvements to ActiveRecordStore's gc rake task - 847e19bf60a6b8163c1e0d2e96dbd805c64e2880
|
data/INSTALL.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Ruby OpenID Library Installation
|
2
|
+
|
3
|
+
## Rubygems Installation
|
4
|
+
|
5
|
+
Rubygems is a tool for installing ruby libraries and their
|
6
|
+
dependancies. If you have rubygems installed, simply:
|
7
|
+
|
8
|
+
gem install ruby-openid
|
9
|
+
|
10
|
+
## Manual Installation
|
11
|
+
|
12
|
+
Unpack the archive and run setup.rb to install:
|
13
|
+
|
14
|
+
ruby setup.rb
|
15
|
+
|
16
|
+
setup.rb installs the library into your system ruby. If don't want to
|
17
|
+
add openid to you system ruby, you may instead add the `lib` directory of
|
18
|
+
the extracted tarball to your RUBYLIB environment variable:
|
19
|
+
|
20
|
+
$ export RUBYLIB=${RUBYLIB}:/path/to/ruby-openid/lib
|
21
|
+
|
22
|
+
## Testing the Installation
|
23
|
+
|
24
|
+
Make sure everything installed ok:
|
25
|
+
|
26
|
+
$> irb
|
27
|
+
irb$> require "openid"
|
28
|
+
=> true
|
29
|
+
|
30
|
+
Or, if you installed via rubygems:
|
31
|
+
|
32
|
+
$> irb
|
33
|
+
irb$> require "rubygems"
|
34
|
+
=> true
|
35
|
+
irb$> require_gem "ruby-openid"
|
36
|
+
=> true
|
37
|
+
|
38
|
+
## Run the test suite
|
39
|
+
|
40
|
+
Go into the test directory and execute the `runtests.rb` script.
|
41
|
+
|
42
|
+
## Next steps
|
43
|
+
|
44
|
+
* Run `consumer.rb` in the examples directory.
|
45
|
+
* Get started writing your own consumer using OpenID::Consumer
|
46
|
+
* Write your own server with `OpenID::Server`
|
47
|
+
* Use the `OpenIDLoginGenerator`! Read `example/README` for more info.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Ruby OpenID
|
2
|
+
|
3
|
+
A Ruby library for verifying and serving OpenID identities.
|
4
|
+
|
5
|
+
[](http://travis-ci.org/openid/ruby-openid)
|
6
|
+
|
7
|
+
## Features
|
8
|
+
|
9
|
+
* Easy to use API for verifying OpenID identites - OpenID::Consumer
|
10
|
+
* Support for serving OpenID identites - OpenID::Server
|
11
|
+
* Does not depend on underlying web framework
|
12
|
+
* Supports multiple storage mechanisms (Filesystem, ActiveRecord, Memory)
|
13
|
+
* Example code to help you get started, including:
|
14
|
+
* Ruby on Rails based consumer and server
|
15
|
+
* OpenIDLoginGenerator for quickly getting creating a rails app that uses
|
16
|
+
OpenID for authentication
|
17
|
+
* ActiveRecordOpenIDStore plugin
|
18
|
+
* Comprehensive test suite
|
19
|
+
* Supports both OpenID 1 and OpenID 2 transparently
|
20
|
+
|
21
|
+
## Installing
|
22
|
+
|
23
|
+
Before running the examples or writing your own code you'll need to install
|
24
|
+
the library. See the INSTALL file or use rubygems:
|
25
|
+
|
26
|
+
gem install ruby-openid
|
27
|
+
|
28
|
+
Check the installation:
|
29
|
+
|
30
|
+
$ irb
|
31
|
+
irb> require 'rubygems'
|
32
|
+
=> false
|
33
|
+
irb> gem 'ruby-openid'
|
34
|
+
=> true
|
35
|
+
|
36
|
+
The library is known to work with Ruby 1.8.4 on Unix, Max OSX and
|
37
|
+
Win32. Examples have been tested with Rails 1 to 3.
|
38
|
+
|
39
|
+
## Getting Started
|
40
|
+
|
41
|
+
The best way to start is to look at the rails_openid example.
|
42
|
+
You can run it with:
|
43
|
+
|
44
|
+
cd examples/rails_openid
|
45
|
+
script/server
|
46
|
+
|
47
|
+
If you are writing an OpenID Relying Party, a good place to start is:
|
48
|
+
`examples/rails_openid/app/controllers/consumer_controller.rb`
|
49
|
+
|
50
|
+
And if you are writing an OpenID provider:
|
51
|
+
`examples/rails_openid/app/controllers/server_controller.rb`
|
52
|
+
|
53
|
+
The library code is quite well documented, so don't be squeamish, and
|
54
|
+
look at the library itself if there's anything you don't understand in
|
55
|
+
the examples.
|
56
|
+
|
57
|
+
## Homepage
|
58
|
+
|
59
|
+
* [GitHub](http://github.com/openid/ruby-openid)
|
60
|
+
* [Website](http://openid.net/)
|
61
|
+
|
62
|
+
## Community
|
63
|
+
|
64
|
+
Discussion regarding the Ruby OpenID library and other JanRain OpenID
|
65
|
+
libraries takes place on the [OpenID mailing list](http://openid.net/developers/dev-mailing-lists/).
|
66
|
+
|
67
|
+
Please join this list to discuss, ask implementation questions, report
|
68
|
+
bugs, etc. Also check out the openid channel on the freenode IRC
|
69
|
+
network.
|
70
|
+
|
71
|
+
If you have a bugfix or feature you'd like to contribute, don't
|
72
|
+
hesitate to send it to us: [How to contribute](http://openidenabled.com/contribute/).
|
73
|
+
|
74
|
+
## Author
|
75
|
+
|
76
|
+
Copyright 2006-2012, JanRain, Inc.
|
77
|
+
|
78
|
+
Contact openid@janrain.com or visit the [OpenID channel on pibb.com](http://pibb.com/go/openid).
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
Apache Software License. For more information see the LICENSE file.
|
data/{UPGRADE → UPGRADE.md}
RENAMED
@@ -1,125 +1,124 @@
|
|
1
|
-
|
1
|
+
# Upgrading from the OpenID 1.x series library
|
2
2
|
|
3
|
-
|
3
|
+
## Consumer Upgrade
|
4
4
|
|
5
|
-
The flow is largely the same, however there are a number of significant
|
6
|
-
changes.
|
7
|
-
examples/rails_openid/app/controllers/consumer_controller.rb
|
5
|
+
The flow is largely the same, however there are a number of significant
|
6
|
+
changes. The consumer example is helpful to look at:
|
7
|
+
`examples/rails_openid/app/controllers/consumer_controller.rb`
|
8
8
|
|
9
|
-
|
10
|
-
=== Stores
|
9
|
+
### Stores
|
11
10
|
|
12
11
|
You will need to require the file for the store that you are using.
|
13
12
|
For the filesystem store, this is 'openid/stores/filesystem'
|
14
|
-
They are also now in modules.
|
15
|
-
OpenID::Store::Filesystem
|
13
|
+
They are also now in modules. The filesystem store is
|
14
|
+
`OpenID::Store::Filesystem`
|
16
15
|
The format has changed, and you should remove your old store directory.
|
17
16
|
|
18
|
-
The ActiveRecord store (
|
17
|
+
The ActiveRecord store (`examples/active_record_openid_store`) still needs
|
19
18
|
to be put in a plugin directory for your rails app. There's a migration
|
20
|
-
that needs to be run; examine the README in that directory.
|
19
|
+
that needs to be run; examine the `README` in that directory.
|
21
20
|
|
22
21
|
Also, note that the stores now can be garbage collected with the method
|
23
|
-
store.cleanup
|
24
|
-
|
22
|
+
`store.cleanup`
|
25
23
|
|
26
|
-
|
24
|
+
### Starting the OpenID transaction
|
27
25
|
|
28
26
|
The OpenIDRequest object no longer has status codes. Instead,
|
29
27
|
consumer.begin raises an OpenID::OpenIDError if there is a problem
|
30
28
|
initiating the transaction, so you'll want something along the lines of:
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
begin
|
31
|
+
openid_request = consumer.begin(params[:openid_identifier])
|
32
|
+
rescue OpenID::OpenIDError => e
|
33
|
+
# display error e
|
34
|
+
return
|
35
|
+
end
|
36
|
+
#success case
|
39
37
|
|
40
38
|
Data regarding the OpenID server once lived in
|
41
|
-
openid_request.service
|
39
|
+
`openid_request.service`
|
42
40
|
|
43
41
|
The corresponding object in the 2.0 lib can be retrieved with
|
44
|
-
openid_request.endpoint
|
42
|
+
`openid_request.endpoint`
|
45
43
|
|
46
44
|
Getting the unverified identifier: Where you once had
|
47
|
-
openid_request.identity_url
|
45
|
+
`openid_request.identity_url`
|
48
46
|
you will now want
|
49
|
-
openid_request.endpoint.claimed_id
|
47
|
+
`openid_request.endpoint.claimed_id`
|
50
48
|
which might be different from what you get at the end of the transaction,
|
51
49
|
since it is now possible for users to enter their server's url directly.
|
52
50
|
|
53
51
|
Arguments on the return_to URL are now verified, so if you want to add
|
54
52
|
additional arguments to the return_to url, use
|
55
|
-
openid_request.return_to_args['param'] = value
|
53
|
+
`openid_request.return_to_args['param'] = value`
|
56
54
|
|
57
55
|
Generating the redirect is the same as before, but add any extensions
|
58
56
|
first.
|
59
57
|
|
60
58
|
If you need to set up an SSL certificate authority list for the fetcher,
|
61
|
-
use the 'ca_file' attr_accessor on the OpenID::StandardFetcher
|
62
|
-
changed from 'ca_path' in the 1.x.x series library.
|
63
|
-
OpenID.fetcher.ca_file = '/path/to/ca.list'
|
59
|
+
use the 'ca_file' attr_accessor on the `OpenID::StandardFetcher`. This has
|
60
|
+
changed from 'ca_path' in the 1.x.x series library. That is, set
|
61
|
+
`OpenID.fetcher.ca_file = '/path/to/ca.list'`
|
64
62
|
before calling consumer.begin.
|
65
63
|
|
66
|
-
|
64
|
+
### Requesting Simple Registration Data
|
67
65
|
|
68
66
|
You'll need to require the code for the extension
|
69
|
-
|
67
|
+
|
68
|
+
require 'openid/extensions/sreg'
|
70
69
|
|
71
70
|
The new code for adding an SReg request now looks like:
|
72
71
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
sreg_request = OpenID::SReg::Request.new
|
73
|
+
sreg_request.request_fields(['email', 'dob'], true) # required
|
74
|
+
sreg_request.request_fields(['nickname', 'fullname'], false) # optional
|
75
|
+
sreg_request.policy_url = policy_url
|
76
|
+
openid_request.add_extension(sreg_request)
|
78
77
|
|
79
78
|
The code for adding other extensions is similar. Code for the Attribute
|
80
79
|
Exchange (AX) and Provider Authentication Policy Extension (PAPE) are
|
81
80
|
included with the library, and additional extensions can be implemented
|
82
|
-
subclassing OpenID::Extension
|
81
|
+
subclassing `OpenID::Extension`.
|
83
82
|
|
84
|
-
|
85
|
-
=== Completing the transaction
|
83
|
+
### Completing the transaction
|
86
84
|
|
87
85
|
The return_to and its arguments are verified, so you need to pass in
|
88
86
|
the base URL and the arguments. With Rails, the params method mashes
|
89
87
|
together parameters from GET, POST, and the path, so you'll need to pull
|
90
88
|
off the path "parameters" with something like
|
91
89
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
90
|
+
return_to = url_for(:only_path => false,
|
91
|
+
:controller => 'openid',
|
92
|
+
:action => 'complete')
|
93
|
+
parameters = params.reject{|k,v| request.path_parameters[k] }
|
94
|
+
openid_response = consumer.complete(parameters, return_to)
|
97
95
|
|
98
96
|
The response still uses the status codes, but they are now namespaced
|
99
|
-
slightly differently, for example OpenID::Consumer::SUCCESS
|
97
|
+
slightly differently, for example `OpenID::Consumer::SUCCESS`
|
100
98
|
|
101
99
|
In the case of failure, the error message is now found in
|
102
|
-
openid_response.message
|
100
|
+
`openid_response.message`
|
103
101
|
|
104
102
|
The identifier to display to the user can be found in
|
105
|
-
openid_response.endpoint.display_identifier
|
103
|
+
`openid_response.endpoint.display_identifier`
|
106
104
|
|
107
105
|
The Simple Registration response can be read from the OpenID response
|
108
106
|
with
|
109
|
-
sreg_response = OpenID::SReg::Response.from_success_response(openid_response)
|
110
|
-
nickname = sreg_response['nickname']
|
111
|
-
# etc.
|
112
107
|
|
108
|
+
sreg_response = OpenID::SReg::Response.from_success_response(openid_response)
|
109
|
+
nickname = sreg_response['nickname']
|
110
|
+
# etc.
|
113
111
|
|
114
|
-
|
112
|
+
## Server Upgrade
|
115
113
|
|
116
114
|
The server code is mostly the same as before, with the exception of
|
117
|
-
extensions.
|
115
|
+
extensions. Also, you must pass in the endpoint URL to the server
|
118
116
|
constructor:
|
119
|
-
@server = OpenID::Server.new(store, server_url)
|
120
117
|
|
121
|
-
|
122
|
-
|
118
|
+
@server = OpenID::Server.new(store, server_url)
|
119
|
+
|
120
|
+
I recommend looking at
|
121
|
+
`examples/rails_openid/app/controllers/server_controller.rb`
|
123
122
|
for an example of the new way of doing extensions.
|
124
123
|
|
125
124
|
--
|
@@ -44,9 +44,11 @@ You may garbage collect unused nonces and expired associations using
|
|
44
44
|
the gc instance method of ActiveRecordOpenIDStore. Hook it up to a
|
45
45
|
task in your app's Rakefile like so:
|
46
46
|
|
47
|
-
desc 'GC OpenID store'
|
47
|
+
desc 'GC OpenID store, deleting expired nonces and associations'
|
48
48
|
task :gc_openid_store => :environment do
|
49
|
-
|
49
|
+
require 'openid_ar_store'
|
50
|
+
nonces, associations = ActiveRecordStore.new.cleanup
|
51
|
+
puts "Deleted #{nonces} nonces, #{associations} associations"
|
50
52
|
end
|
51
53
|
|
52
54
|
Run it by typing:
|
@@ -2,7 +2,7 @@
|
|
2
2
|
class AddOpenIdStoreToDb < ActiveRecord::Migration
|
3
3
|
def self.up
|
4
4
|
create_table "open_id_associations", :force => true do |t|
|
5
|
-
t.column "server_url", :
|
5
|
+
t.column "server_url", :string, :null => false
|
6
6
|
t.column "handle", :string, :null => false
|
7
7
|
t.column "secret", :binary, :null => false
|
8
8
|
t.column "issued", :integer, :null => false
|
@@ -1,16 +1,10 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
|
-
# load the openid library, first trying rubygems
|
4
|
-
#begin
|
5
|
-
# require "rubygems"
|
6
|
-
# require_gem "ruby-openid", ">= 1.0"
|
7
|
-
#rescue LoadError
|
8
3
|
require "openid"
|
9
4
|
require "openid/consumer/discovery"
|
10
5
|
require 'openid/extensions/sreg'
|
11
6
|
require 'openid/extensions/pape'
|
12
7
|
require 'openid/store/filesystem'
|
13
|
-
#end
|
14
8
|
|
15
9
|
class ServerController < ApplicationController
|
16
10
|
|
data/lib/openid.rb
CHANGED
data/lib/openid/dh.rb
CHANGED
@@ -57,7 +57,7 @@ module OpenID
|
|
57
57
|
end
|
58
58
|
|
59
59
|
if String.method_defined? :bytes
|
60
|
-
s.bytes.zip(t.bytes).map{|sb,tb| sb^tb}.pack('C*')
|
60
|
+
s.bytes.to_a.zip(t.bytes.to_a).map{|sb,tb| sb^tb}.pack('C*')
|
61
61
|
else
|
62
62
|
indices = 0...(s.length)
|
63
63
|
chrs = indices.collect {|i| (s[i]^t[i]).chr}
|
data/lib/openid/extensions/ax.rb
CHANGED
@@ -27,6 +27,13 @@ module OpenID
|
|
27
27
|
attr_accessor :ns_alias, :mode, :ns_uri
|
28
28
|
|
29
29
|
NS_URI = 'http://openid.net/srv/ax/1.0'
|
30
|
+
|
31
|
+
begin
|
32
|
+
Message.register_namespace_alias(NS_URI, 'ax')
|
33
|
+
rescue NamespaceAliasRegistrationError => e
|
34
|
+
Util.log(e)
|
35
|
+
end
|
36
|
+
|
30
37
|
def initialize
|
31
38
|
@ns_alias = 'ax'
|
32
39
|
@ns_uri = NS_URI
|
@@ -38,7 +45,7 @@ module OpenID
|
|
38
45
|
# Raise an exception if the mode in the attribute exchange
|
39
46
|
# arguments does not match what is expected for this class.
|
40
47
|
def check_mode(ax_args)
|
41
|
-
actual_mode = ax_args['mode']
|
48
|
+
actual_mode = ax_args ? ax_args['mode'] : nil
|
42
49
|
if actual_mode != @mode
|
43
50
|
raise Error, "Expected mode #{mode.inspect}, got #{actual_mode.inspect}"
|
44
51
|
end
|
@@ -110,7 +117,7 @@ module OpenID
|
|
110
117
|
class FetchRequest < AXMessage
|
111
118
|
attr_reader :requested_attributes
|
112
119
|
attr_accessor :update_url
|
113
|
-
|
120
|
+
|
114
121
|
MODE = 'fetch_request'
|
115
122
|
|
116
123
|
def initialize(update_url = nil)
|
@@ -137,7 +144,7 @@ module OpenID
|
|
137
144
|
aliases = NamespaceMap.new
|
138
145
|
required = []
|
139
146
|
if_available = []
|
140
|
-
ax_args = new_args
|
147
|
+
ax_args = new_args
|
141
148
|
@requested_attributes.each{|type_uri, attribute|
|
142
149
|
if attribute.ns_alias
|
143
150
|
name = aliases.add_alias(type_uri, attribute.ns_alias)
|
@@ -296,12 +303,21 @@ module OpenID
|
|
296
303
|
@data.each{|type_uri, values|
|
297
304
|
name = aliases.add(type_uri)
|
298
305
|
ax_args['type.'+name] = type_uri
|
299
|
-
|
306
|
+
if values.size > 1
|
307
|
+
ax_args['count.'+name] = values.size.to_s
|
300
308
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
309
|
+
values.each_with_index{|value, i|
|
310
|
+
key = "value.#{name}.#{i+1}"
|
311
|
+
ax_args[key] = value
|
312
|
+
}
|
313
|
+
# for attributes with only a single value, use a
|
314
|
+
# nice shortcut to only show the value w/o the count
|
315
|
+
else
|
316
|
+
values.each do |value|
|
317
|
+
key = "value.#{name}"
|
318
|
+
ax_args[key] = value
|
319
|
+
end
|
320
|
+
end
|
305
321
|
}
|
306
322
|
return ax_args
|
307
323
|
end
|
@@ -328,7 +344,7 @@ module OpenID
|
|
328
344
|
if count_s.nil?
|
329
345
|
value = ax_args['value.'+name]
|
330
346
|
if value.nil?
|
331
|
-
raise IndexError, "Missing #{'value.'+name} in FetchResponse"
|
347
|
+
raise IndexError, "Missing #{'value.'+name} in FetchResponse"
|
332
348
|
elsif value.empty?
|
333
349
|
values = []
|
334
350
|
else
|
@@ -365,7 +381,7 @@ module OpenID
|
|
365
381
|
def get(type_uri)
|
366
382
|
@data[type_uri]
|
367
383
|
end
|
368
|
-
|
384
|
+
|
369
385
|
# retrieve the list of values for this attribute
|
370
386
|
def [](type_uri)
|
371
387
|
@data[type_uri]
|
@@ -381,11 +397,17 @@ module OpenID
|
|
381
397
|
# A fetch_response attribute exchange message
|
382
398
|
class FetchResponse < KeyValueMessage
|
383
399
|
attr_reader :update_url
|
400
|
+
# Use the aliases variable to manually add alias names in the response.
|
401
|
+
# They'll be returned to the client in the format:
|
402
|
+
# openid.ax.type.email=http://openid.net/schema/contact/internet/email
|
403
|
+
# openid.ax.value.email=guy@example.com
|
404
|
+
attr_accessor :aliases
|
384
405
|
|
385
406
|
def initialize(update_url = nil)
|
386
407
|
super()
|
387
408
|
@mode = 'fetch_response'
|
388
409
|
@update_url = update_url
|
410
|
+
@aliases = NamespaceMap.new
|
389
411
|
end
|
390
412
|
|
391
413
|
# Serialize this object into arguments in the attribute
|
@@ -394,7 +416,6 @@ module OpenID
|
|
394
416
|
# validated against this request, and empty responses for requested
|
395
417
|
# fields with no data will be sent.
|
396
418
|
def get_extension_args(request = nil)
|
397
|
-
aliases = NamespaceMap.new
|
398
419
|
zero_value_types = []
|
399
420
|
|
400
421
|
if request
|
@@ -412,28 +433,29 @@ module OpenID
|
|
412
433
|
# Copy the aliases from the request so that reading
|
413
434
|
# the response in light of the request is easier
|
414
435
|
if attr_info.ns_alias.nil?
|
415
|
-
aliases.add(attr_info.type_uri)
|
436
|
+
@aliases.add(attr_info.type_uri)
|
416
437
|
else
|
417
|
-
aliases.add_alias(attr_info.type_uri, attr_info.ns_alias)
|
438
|
+
@aliases.add_alias(attr_info.type_uri, attr_info.ns_alias)
|
418
439
|
end
|
419
440
|
values = @data[attr_info.type_uri]
|
420
441
|
if values.empty? # @data defaults to []
|
421
442
|
zero_value_types << attr_info
|
422
443
|
end
|
444
|
+
|
423
445
|
if attr_info.count != UNLIMITED_VALUES and attr_info.count < values.size
|
424
446
|
raise Error, "More than the number of requested values were specified for #{attr_info.type_uri.inspect}"
|
425
447
|
end
|
426
448
|
}
|
427
449
|
end
|
428
450
|
|
429
|
-
kv_args = _get_extension_kv_args(aliases)
|
451
|
+
kv_args = _get_extension_kv_args(@aliases)
|
430
452
|
|
431
453
|
# Add the KV args into the response with the args that are
|
432
454
|
# unique to the fetch_response
|
433
455
|
ax_args = new_args
|
434
456
|
|
435
457
|
zero_value_types.each{|attr_info|
|
436
|
-
name = aliases.get_alias(attr_info.type_uri)
|
458
|
+
name = @aliases.get_alias(attr_info.type_uri)
|
437
459
|
kv_args['type.' + name] = attr_info.type_uri
|
438
460
|
kv_args['count.' + name] = '0'
|
439
461
|
}
|
@@ -469,26 +491,26 @@ module OpenID
|
|
469
491
|
|
470
492
|
# A store request attribute exchange message representation
|
471
493
|
class StoreRequest < KeyValueMessage
|
472
|
-
|
494
|
+
|
473
495
|
MODE = 'store_request'
|
474
|
-
|
496
|
+
|
475
497
|
def initialize
|
476
498
|
super
|
477
499
|
@mode = MODE
|
478
500
|
end
|
479
|
-
|
501
|
+
|
480
502
|
# Extract a StoreRequest from an OpenID message
|
481
503
|
# message: OpenID::Message
|
482
504
|
# return a StoreRequest or nil if AX arguments are not present
|
483
505
|
def self.from_openid_request(oidreq)
|
484
|
-
message = oidreq.message
|
506
|
+
message = oidreq.message
|
485
507
|
ax_args = message.get_args(NS_URI)
|
486
508
|
return nil if ax_args.empty? or ax_args['mode'] != MODE
|
487
509
|
req = new
|
488
510
|
req.parse_extension_args(ax_args)
|
489
511
|
req
|
490
512
|
end
|
491
|
-
|
513
|
+
|
492
514
|
def get_extension_args(aliases=nil)
|
493
515
|
ax_args = new_args
|
494
516
|
kv_args = _get_extension_kv_args(aliases)
|
@@ -516,13 +538,13 @@ module OpenID
|
|
516
538
|
end
|
517
539
|
@error_message = error_message
|
518
540
|
end
|
519
|
-
|
541
|
+
|
520
542
|
def self.from_success_response(success_response)
|
521
543
|
resp = nil
|
522
544
|
ax_args = success_response.message.get_args(NS_URI)
|
523
545
|
resp = ax_args.key?('error') ? new(false, ax_args['error']) : new
|
524
546
|
end
|
525
|
-
|
547
|
+
|
526
548
|
def succeeded?
|
527
549
|
@mode == SUCCESS_MODE
|
528
550
|
end
|