barx 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +21 -0
- data/README +11 -0
- data/examples/README +78 -0
- data/examples/dix +47 -0
- data/examples/proxri +41 -0
- data/examples/xrioid +66 -0
- data/lib/barx.rb +9 -0
- data/lib/httpclient/cacert.p7s +952 -0
- data/lib/httpclient/cookie.rb +541 -0
- data/lib/httpclient/http.rb +602 -0
- data/lib/httpclient.rb +2054 -0
- data/lib/xri_parser.rb +163 -0
- data/lib/xri_resolver.rb +1056 -0
- data/test/authority_parser_profile.rb +14 -0
- data/test/test_helper.rb +7 -0
- data/test/unit/all.rb +7 -0
- data/test/unit/authority_parser_test.rb +300 -0
- data/test/unit/input_param_parser_test.rb +93 -0
- data/test/unit/multi_stage_resolution_test.rb +44 -0
- data/test/unit/sep_selection_test.rb +87 -0
- data/test/xrds_sources/empty_sels_no_append_qxri_sep +13 -0
- data/test/xrds_sources/empty_sels_sep +13 -0
- data/test/xrds_sources/first_stage1 +38 -0
- data/test/xrds_sources/no_svc_sep +8 -0
- data/test/xrds_sources/second_stage1 +26 -0
- data/test/xrds_sources/sep1 +31 -0
- metadata +82 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2007 Victor Grey and Kermit Snelson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
The barx gem provides XRI resolution libraries for use in other applications.
|
2
|
+
|
3
|
+
The basic API is as follows:
|
4
|
+
require 'barx'
|
5
|
+
xri = XriParser::AuthorityParser.parse(QXRI)
|
6
|
+
inputs = XriResolver::ParseInputParameters.new(params_hash)
|
7
|
+
xrds = XriResolver::AuthorityResolver.resolve(xri, inputs)
|
8
|
+
|
9
|
+
In the above example, QXRI refers to qxri as defined in section 7 of <http://www.oasis-open.org/committees/download.php/25741/xri-resolution-v2.0-wd-11-ed-06.pdf>, and params_hash is a Ruby hash of the keys and values in the Query String part of the QXRI or the relevant HTTP Accept header.
|
10
|
+
|
11
|
+
See examples/README for more information. There is also a full featured XRI proxy resolver, barx-proxy, available at <http://rubyforge.org/projects/barx/>.
|
data/examples/README
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
:::
|
2
|
+
::: API Examples
|
3
|
+
:::
|
4
|
+
|
5
|
+
For a Ruby script to use the BARX API, the barx gem must first
|
6
|
+
be installed. Consult http://www.rubygems.org for instructions.
|
7
|
+
|
8
|
+
Once this is done, a Ruby application uses the API as follows:
|
9
|
+
|
10
|
+
require 'barx'
|
11
|
+
|
12
|
+
ap = XriParser::AuthorityParser.parse(xri)
|
13
|
+
ip = XriResolver::ParseInputParameters.new
|
14
|
+
ar = XriResolver::AuthorityResolver.resolve(ap, ip)
|
15
|
+
|
16
|
+
This directory contains three examples of applications written
|
17
|
+
using the BARX API which might also be of practical use.
|
18
|
+
|
19
|
+
:::
|
20
|
+
::: dix
|
21
|
+
:::
|
22
|
+
|
23
|
+
dix is a command-line XRI resolver inspired by the DNS/BIND
|
24
|
+
utility "dig".
|
25
|
+
|
26
|
+
Usage: dix [options] xri
|
27
|
+
-r, --resmed string resolution media type
|
28
|
+
-t, --svctyp string service type
|
29
|
+
-m, --medtyp string service media type
|
30
|
+
-s, --doseps perform SEP resolution
|
31
|
+
|
32
|
+
Examples:
|
33
|
+
|
34
|
+
dix =kermit
|
35
|
+
dix "=kermit*business"
|
36
|
+
dix --resmed application/xrds+xml =kermit
|
37
|
+
dix --doseps --resmed application/xrds+xml =kermit
|
38
|
+
dix -t http://openid.net/signon/1.0 -s "=kermit*business"
|
39
|
+
|
40
|
+
:::
|
41
|
+
::: proxri
|
42
|
+
:::
|
43
|
+
|
44
|
+
proxri is an XRI proxy resolver implemented as a CGI script.
|
45
|
+
|
46
|
+
To install, simply copy it to Apache's cgi-bin directory and
|
47
|
+
make it executable. A standard XRI proxy resolver interface
|
48
|
+
can be made available to end users via Apache's mod_rewrite
|
49
|
+
directives in the Web server's .htaccess file.
|
50
|
+
|
51
|
+
For example, to make your proxy resolver available in a standard
|
52
|
+
way as follows:
|
53
|
+
|
54
|
+
http://xri.example.com/=kermit
|
55
|
+
http://xri.example.com/=kermit?_xrd_r=application/xrds+xml [etc.]
|
56
|
+
|
57
|
+
the .htaccess file at example.com could contain the following
|
58
|
+
mod_rewrite directives:
|
59
|
+
|
60
|
+
RewriteCond %{HTTP_HOST} ^xri\..*
|
61
|
+
RewriteRule ^([=@].*)$ /cgi-bin/proxri?qxri=$1&%{QUERY_STRING}
|
62
|
+
|
63
|
+
:::
|
64
|
+
::: xrioid
|
65
|
+
:::
|
66
|
+
|
67
|
+
xrioid is a special XRI service that converts i-names into valid
|
68
|
+
OpenIDs. They may be used to log in at any OpenID Relying Party,
|
69
|
+
even if that site's OpenID libraries do not natively support XRI.
|
70
|
+
|
71
|
+
It is an implementation of the OpenID Discovery Proxy Service idea
|
72
|
+
proposed by Drummond Reed in June 2007 and described on the i-names
|
73
|
+
Development Wiki:
|
74
|
+
|
75
|
+
http://dev.inames.net/wiki/OpenID_Discovery_Proxy_Service
|
76
|
+
|
77
|
+
Like proxri, xrioid is implemented as a CGI script and may be
|
78
|
+
installed in a similar way.
|
data/examples/dix
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'barx'
|
5
|
+
|
6
|
+
opts = Struct.new(:r, :t, :m, :sep).new
|
7
|
+
|
8
|
+
op = OptionParser.new
|
9
|
+
op.on("-r", "--resmed string", String, "resolution media type") { |val| opts.r = val }
|
10
|
+
op.on("-t", "--svctyp string", String, "service type") { |val| opts.t = val }
|
11
|
+
op.on("-m", "--medtyp string", String, "service media type") { |val| opts.m = val }
|
12
|
+
op.on("-s", "--doseps", TrueClass, "perform SEP resolution") { |val| opts.sep = true }
|
13
|
+
|
14
|
+
if op.parse(*ARGV).empty?
|
15
|
+
puts op.to_s
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
xri = op.parse(*ARGV).first
|
20
|
+
|
21
|
+
begin
|
22
|
+
ap = XriParser::AuthorityParser.parse(xri)
|
23
|
+
|
24
|
+
rp = XriResolver::ParseInputParameters.new
|
25
|
+
rp.resolution_media_type = opts.r
|
26
|
+
rp.service_type = opts.t
|
27
|
+
rp.service_media_type = opts.m
|
28
|
+
rp.sep = opts.sep
|
29
|
+
|
30
|
+
ar = XriResolver::AuthorityResolver.resolve(ap, rp)
|
31
|
+
|
32
|
+
case rp.resolution_media_type
|
33
|
+
when 'application/xrds+xml'
|
34
|
+
ar.to_xrds.write $stdout, indent=0; puts
|
35
|
+
when 'application/xrd+xml'
|
36
|
+
ar.last_xrd.write $stdout, indent=0; puts
|
37
|
+
else
|
38
|
+
unless ar.to_urilist.empty?
|
39
|
+
puts ar.to_urilist.join("\n") << "\n"
|
40
|
+
else
|
41
|
+
puts "no services selected for this XRI"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
rescue Exception => e
|
46
|
+
puts e.message
|
47
|
+
end
|
data/examples/proxri
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
require 'barx'
|
4
|
+
|
5
|
+
cgi = CGI.new
|
6
|
+
|
7
|
+
begin
|
8
|
+
pms = Hash.new; cgi.params.keys.each { |key| pms[key] = cgi.params[key].join.tr(' ', '+') }
|
9
|
+
|
10
|
+
ap = XriParser::AuthorityParser.parse(pms['qxri'])
|
11
|
+
ip = XriResolver::ParseInputParameters.new(pms, cgi.accept)
|
12
|
+
ar = XriResolver::AuthorityResolver.resolve(ap, ip)
|
13
|
+
|
14
|
+
unless ip.resolution_media_type.nil? or ip.resolution_media_type.empty?
|
15
|
+
case ip.resolution_media_type
|
16
|
+
when 'application/xrds+xml'
|
17
|
+
cgi.out(pms['demo'] ? 'application/xml' : ip.resolution_media_type) do
|
18
|
+
ar.to_s
|
19
|
+
end
|
20
|
+
when 'application/xrd+xml'
|
21
|
+
cgi.out(pms['demo'] ? 'application/xml' : ip.resolution_media_type) do
|
22
|
+
ar.last_xrd_doc.to_s
|
23
|
+
end
|
24
|
+
when 'text/uri-list'
|
25
|
+
cgi.out(pms['demo'] ? 'text/plain' : ip.resolution_media_type) do
|
26
|
+
ar.to_urilist.join("\n") << "\n"
|
27
|
+
end
|
28
|
+
else
|
29
|
+
cgi.out("text/plain") { "invalid media type" }
|
30
|
+
end
|
31
|
+
else
|
32
|
+
unless ar.to_urilist.empty?
|
33
|
+
cgi.out("Location" => ar.to_urilist.first) { ar.to_urilist.first }
|
34
|
+
else
|
35
|
+
cgi.out("text/plain") { "no services selected for this XRI" }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
rescue Exception => e
|
40
|
+
cgi.out("text/plain") { e.message }
|
41
|
+
end
|
data/examples/xrioid
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
require 'barx'
|
4
|
+
|
5
|
+
cgi = CGI.new
|
6
|
+
|
7
|
+
begin
|
8
|
+
ap = XriParser::AuthorityParser.parse(CGI.unescape(cgi.params['iname'].first))
|
9
|
+
ip = XriResolver::ParseInputParameters.new
|
10
|
+
ip.sep = true
|
11
|
+
ip.nodefault_t = true
|
12
|
+
ip.service_type = 'http://openid.net/signon/1.0'
|
13
|
+
ip.resolution_media_type = 'application/xrds+xml'
|
14
|
+
ar = XriResolver::AuthorityResolver.resolve(ap, ip)
|
15
|
+
|
16
|
+
if idp = ar.to_urilist.first
|
17
|
+
unless REXML::XPath.match(xrd = ar.last_xrd, "//*[local-name()='Delegate']").first
|
18
|
+
dlg = REXML::Element.new('openid:Delegate')
|
19
|
+
dlg.add_namespace('openid', 'http://openid.net/xmlns/1.0')
|
20
|
+
dlg.text = "xri://#{ap.authority}"
|
21
|
+
xrd.elements['Service'].add_element(dlg)
|
22
|
+
end
|
23
|
+
|
24
|
+
xrds = ar.to_xrds.root.clone
|
25
|
+
xrds.add_element(xrd)
|
26
|
+
|
27
|
+
oid = Struct.new(:xri, :dlg, :idp).new
|
28
|
+
oid.xri = ap.authority
|
29
|
+
oid.dlg = REXML::XPath.match(xrd, "//*[local-name()='Delegate']").first.text
|
30
|
+
oid.idp = idp
|
31
|
+
|
32
|
+
if (cgi.accept and cgi.accept.include?('application/xrds+xml')) or ap.path == '/xrds'
|
33
|
+
cgi.out("application/xrds+xml") { xrds.to_s }
|
34
|
+
else
|
35
|
+
out = String.new
|
36
|
+
out << "<html>\n"
|
37
|
+
out << "<head>\n"
|
38
|
+
out << "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\n"
|
39
|
+
out << "<title>xri://#{oid.xri} OpenID</title>\n"
|
40
|
+
out << "<style type=\"text/css\">.variable {color: red}</style>\n"
|
41
|
+
out << "<link rel=\"openid.server\" href=\"#{oid.idp}\" />\n"
|
42
|
+
out << "<link rel=\"openid.delegate\" href=\"#{oid.dlg}\" />\n"
|
43
|
+
out << "<meta http-equiv=\"X-XRDS-Location\" content=\"http://#{cgi.server_name}/#{oid.xri}/xrds\" />\n"
|
44
|
+
out << "<meta http-equiv=\"X-Yadis-Location\" content=\"http://#{cgi.server_name}/#{oid.xri}/xrds\" />\n"
|
45
|
+
out << "</head>\n"
|
46
|
+
out << "<body>\n"
|
47
|
+
out << "<h2>Here is your XRI-powered OpenID!</h2>\n"
|
48
|
+
out << "<p>The URL of this page may be used to access the "
|
49
|
+
out << "<a href=\"http://openid.net\">OpenID</a> service configured "
|
50
|
+
out << "at <span class=\"variable\">xri://#{oid.xri}</span>.</p>\n"
|
51
|
+
out << "<p>Use it as your username on any Web sites that support "
|
52
|
+
out << "OpenID, including those that do not natively support the "
|
53
|
+
out << "<a href=\"http://xdi.org\">XRI</a> standard.</p>\n"
|
54
|
+
out << "<p><b>Identity Provider:</b> <span class=\"variable\">#{oid.idp}</span><br/>\n"
|
55
|
+
out << "<b>Claimed Identifier:</b> <span class=\"variable\">#{oid.dlg}</span></p>\n"
|
56
|
+
out << "</body>\n"
|
57
|
+
out << "</html>\n"
|
58
|
+
cgi.out("text/html") { out }
|
59
|
+
end
|
60
|
+
else
|
61
|
+
cgi.out("text/plain") { "no OpenID service configured at this XRI" }
|
62
|
+
end
|
63
|
+
|
64
|
+
rescue Exception => e
|
65
|
+
cgi.out("text/plain") { e.message }
|
66
|
+
end
|