ruby-openid 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby-openid might be problematic. Click here for more details.

data/INSTALL CHANGED
@@ -7,19 +7,41 @@ This library depends on the Ruby Yadis library available at:
7
7
  http://www.openidenabled.com/yadis/libraries/ruby/about/
8
8
 
9
9
  Please make sure you have the Yadis library installed, or use
10
- rubygems for installation.
10
+ rubygems for installation
11
11
 
12
- == Installation
12
+ == Rubygems Installation
13
13
 
14
- Unpack the archive and run setup.rb (you may need to be root)
14
+ Rubygems is a tool for installing ruby libraries and their
15
+ dependancies. If you have rubygems installed, simply:
16
+
17
+ gem install ruby-openid
18
+
19
+ == Manual Installation
20
+
21
+ Unpack the archive and run setup.rb to install:
15
22
 
16
23
  ruby setup.rb
17
24
 
18
- setup.rb installs the library into your system ruby. If don't want to add openid to you system ruby, make sure to add the *lib* directory of the extracted tarball to your RUBYLIB environment variable.
25
+ setup.rb installs the library into your system ruby. If don't want to
26
+ add openid to you system ruby, you may instead add the *lib* directory of
27
+ the extracted tarball to your RUBYLIB environment variable:
28
+
29
+ $ export RUBYLIB=${RUBYLIB}:/path/to/ruby-openid/lib
30
+
31
+
32
+ == Testing the Installation
19
33
 
20
34
  Make sure everything installed ok:
21
35
  $> irb
22
- irb(main):001:0> require "openid/consumer"
36
+ irb$> require "openid"
37
+ => true
38
+
39
+ Or, if you installed via rubygems:
40
+
41
+ $> irb
42
+ irb$> require "rubygems"
43
+ => true
44
+ irb$> require_gem "ruby-openid"
23
45
  => true
24
46
 
25
47
  == Run the test suite
@@ -31,4 +53,4 @@ Go into the test directory and execute the *runtests.rb* script.
31
53
  * Run consumer.rb in the examples directory.
32
54
  * Get started writing your own consumer using OpenID::Consumer
33
55
  * Write your own server with OpenID::Server
34
-
56
+ * Use the OpenIDLoginGenerator! Read example/README for more info.
data/README CHANGED
@@ -18,10 +18,19 @@ A Ruby library for verifying and serving OpenID identities.
18
18
 
19
19
  ==Installing
20
20
  Before running the examples or writing your own code you'll need to install
21
- the library. See the INSTALL file.
21
+ the library. See the INSTALL file or use rubygems:
22
+
23
+ gem intall ruby-openid
24
+
25
+ Check the installation:
26
+
27
+ $ irb
28
+ irb> require 'rubygems'
29
+ irb> require_gem 'ruby-openid'
30
+ => true
22
31
 
23
32
  The library is known to work with Ruby 1.8.4 on Unix, Max OSX and
24
- Win32. Examples were tested with Rails 1.0.
33
+ Win32. Examples were tested with Rails 1.1.
25
34
 
26
35
 
27
36
  ==Getting Started with OpenID::Consumer
@@ -30,6 +39,7 @@ OpenID authentication on your website. The examples contains
30
39
  several working examples to help you get started, and the
31
40
  OpenID::Consumer class is well documented.
32
41
 
42
+ Also, check out the OpenIDLoginGenerator! Read examples/README for more info.
33
43
 
34
44
  ==Serving OpenID with OpenID::Server
35
45
  The examples directory contains fully functional OpenID server that
data/examples/consumer.rb CHANGED
@@ -3,20 +3,21 @@ require "cgi"
3
3
  require "uri"
4
4
  require "pathname"
5
5
 
6
+
6
7
  require "webrick"
7
8
  include WEBrick
8
9
 
9
10
  # load the openid library, first trying rubygems
10
11
  begin
11
- require "rubygems"
12
- require_gem "ruby-openid", ">= 1.0"
13
- rescue LoadError
14
12
  require "openid"
13
+ rescue LoadError
14
+ require "rubygems"
15
+ require_gem "ruby-openid"
15
16
  end
16
17
 
17
18
  ################ start config ##########################
18
- # use your desired store implementation here
19
- store_dir = Pathname.new(Dir.pwd).join("openid-store")
19
+ # use your desired store implementation here.
20
+ store_dir = Pathname.new(Dir.tmpdir).join("openid-store")
20
21
  store = OpenID::FilesystemStore.new(store_dir)
21
22
 
22
23
  $host = "localhost"
@@ -98,7 +99,7 @@ class SimpleServlet < HTTPServlet::AbstractServlet
98
99
  # testing.
99
100
  do_sreg = @req.query.fetch('sreg', nil)
100
101
 
101
- if do_sreg and request.uses_extension?('http://openid.net/sreg/1.0')
102
+ if do_sreg
102
103
  policy_url = self.build_url('/policy')
103
104
  request.add_extension_arg('sreg','policy_url', policy_url)
104
105
  request.add_extension_arg('sreg','required','email,nickname')
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{openid_login_generator}
3
+ s.version = "0.1"
4
+ s.date = %q{2006-06-12}
5
+ s.summary = %q{[Rails] OpenID Login generator.}
6
+ s.require_paths = ["."]
7
+ s.email = %q{brian@janrain.com}
8
+ s.homepage = %q{http://wiki.rubyonrails.org/rails/pages/OpenidLoginGenerator}
9
+ s.description = %q{Generates Rails code implementing an OpenID based login system for your Rails app. Based on the original Rails Login Generator.}
10
+ s.authors = ["Brian Ellin, JanRain Inc."]
11
+ s.files = Dir.glob("{templates/**/*}") + ['USAGE', 'openid_login_generator.rb']
12
+ s.add_dependency('ruby-openid', '>= 1.0.2')
13
+ end
@@ -4,7 +4,7 @@ require "cgi"
4
4
  # load the openid library
5
5
  begin
6
6
  require "rubygems"
7
- require_gem "ruby-openid", ">= 1.0"
7
+ require_gem "ruby-openid", ">= 1.0.2"
8
8
  rescue LoadError
9
9
  require "openid"
10
10
  end
@@ -43,8 +43,6 @@ class <%= class_name %>Controller < ApplicationController
43
43
 
44
44
  # handle the openid server response
45
45
  def complete
46
- token = @params[:token]
47
-
48
46
  response = consumer.complete(@params)
49
47
 
50
48
  case response.status
@@ -0,0 +1,111 @@
1
+ require "pathname"
2
+ require "cgi"
3
+
4
+ # load the openid library
5
+ begin
6
+ require "rubygems"
7
+ require_gem "ruby-openid", ">= 1.0"
8
+ rescue LoadError
9
+ require "openid"
10
+ end
11
+
12
+ class <%= class_name %>Controller < ApplicationController
13
+ layout 'scaffold'
14
+
15
+ # process the login request, disover the openid server, and
16
+ # then redirect.
17
+ def login
18
+ openid_url = @params[:openid_url]
19
+
20
+ if @request.post?
21
+ request = consumer.begin(openid_url)
22
+
23
+ case request.status
24
+ when OpenID::SUCCESS
25
+ return_to = url_for(:action=> 'complete')
26
+ trust_root = url_for(:controller=>'')
27
+
28
+ url = request.redirect_url(trust_root, return_to)
29
+ redirect_to(url)
30
+ return
31
+
32
+ when OpenID::FAILURE
33
+ escaped_url = CGI::escape(openid_url)
34
+ flash[:notice] = "Could not find OpenID server for #{escaped_url}"
35
+
36
+ else
37
+ flash[:notice] = "An unknown error occured."
38
+
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ # handle the openid server response
45
+ def complete
46
+ response = consumer.complete(@params)
47
+
48
+ case response.status
49
+ when OpenID::SUCCESS
50
+
51
+ @user = User.get(response.identity_url)
52
+
53
+ # create user object if one does not exist
54
+ if @user.nil?
55
+ @user = User.new(:openid_url => response.identity_url)
56
+ @user.save
57
+ end
58
+
59
+ # storing both the openid_url and user id in the session for for quick
60
+ # access to both bits of information. Change as needed.
61
+ @session[:user_id] = @user.id
62
+
63
+ flash[:notice] = "Logged in as #{CGI::escape(response.identity_url)}"
64
+
65
+ redirect_to :action => "welcome"
66
+ return
67
+
68
+ when OpenID::FAILURE
69
+ if response.identity_url
70
+ flash[:notice] = "Verification of #{CGI::escape(response.identity_url)} failed."
71
+
72
+ else
73
+ flash[:notice] = 'Verification failed.'
74
+ end
75
+
76
+ when OpenID::CANCEL
77
+ flash[:notice] = 'Verification cancelled.'
78
+
79
+ else
80
+ flash[:notice] = 'Unknown response from OpenID server.'
81
+ end
82
+
83
+ redirect_to :action => 'login'
84
+ end
85
+
86
+ def logout
87
+ @session[:user_id] = nil
88
+ end
89
+
90
+ def welcome
91
+ end
92
+
93
+ private
94
+
95
+ # Get the OpenID::Consumer object.
96
+ def consumer
97
+ # create the OpenID store for storing associations and nonces,
98
+ # putting it in your app's db directory
99
+ store_dir = Pathname.new(RAILS_ROOT).join('db').join('openid-store')
100
+ store = OpenID::FilesystemStore.new(store_dir)
101
+
102
+ return OpenID::Consumer.new(@session, store)
103
+ end
104
+
105
+ # get the logged in user object
106
+ def find_user
107
+ return nil if session[:user_id].nil?
108
+ User.find(session[:user_id])
109
+ end
110
+
111
+ end
@@ -5,7 +5,7 @@ require "openid/util"
5
5
  begin
6
6
  require 'net/https'
7
7
  rescue LoadError
8
- OpenID::Util.log('WARNING: unable no SSL support found. Will not be able to fetch HTTPS URLs!')
8
+ OpenID::Util.log('WARNING: no SSL support found. Will not be able to fetch HTTPS URLs!')
9
9
  HAS_OPENSSL = false
10
10
  require 'net/http'
11
11
  else
data/lib/openid/server.rb CHANGED
@@ -452,6 +452,14 @@ module OpenID
452
452
 
453
453
  q['openid.trust_root'] = @trust_root if @trust_root
454
454
  q['openid.assoc_handle'] = @assoc_handle if @assoc_handle
455
+
456
+ # add other openid stuff into the query (extensions)
457
+ @query.each do |k,v|
458
+ if k.starts_with?('openid.') and not q.has_key?(k)
459
+ q[k] = v
460
+ end
461
+ end
462
+
455
463
  return OpenID::Util.append_args(server_url, q)
456
464
  end
457
465
 
@@ -1,10 +1,10 @@
1
- require 'rexml/document'
1
+ require 'rexml/document'
2
2
 
3
3
  begin
4
- require 'rubygems'
5
- require_gem 'ruby-yadis', '>=0.2.3'
4
+ require 'yadis'
6
5
  rescue LoadError
7
- require 'yadis/service'
6
+ require 'rubygems'
7
+ require_gem 'ruby-yadis'
8
8
  end
9
9
 
10
10
  module OpenID
@@ -24,7 +24,11 @@ module OpenID
24
24
  # internally by the OpenIDConsumer object.
25
25
  class OpenIDServiceEndpoint < ServiceEndpoint
26
26
 
27
- @@namespace = {'openid' => 'http://openid.net/xmlns/1.0'}
27
+ @@namespace = {
28
+ 'xrdsns' => 'xri://$xrds',
29
+ 'xrdns' => 'xri://$xrd*($v*2.0)',
30
+ 'openidns' => 'http://openid.net/xmlns/1.0'
31
+ }
28
32
  attr_accessor :service_types, :uri, :yadis_url, :delegate_url
29
33
 
30
34
  # Class method to produce OpenIDService objects. Call with a Yadis Service
@@ -39,7 +43,8 @@ module OpenID
39
43
  s.yadis_url = service.yadis.uri
40
44
 
41
45
  s.delegate_url = nil
42
- REXML::XPath.each(service.element, 'openid:Delegate', @@namespace) do |e|
46
+ REXML::XPath.each(service.element, 'openidns:Delegate',
47
+ @@namespace) do |e|
43
48
  s.delegate_url = e.text.strip
44
49
  end
45
50
 
@@ -67,7 +72,7 @@ module OpenID
67
72
 
68
73
  # Alias for +supports?+
69
74
  def uses_extension?(extension_url)
70
- return self.supports?(extension_url)
75
+ return supports?(extension_url)
71
76
  end
72
77
 
73
78
  # Same as uses_extension? Checks to see if the provided URL is
@@ -77,7 +82,7 @@ module OpenID
77
82
  # service.supports?('http://openid.net/sreg/1.0')
78
83
  #
79
84
  def supports?(url)
80
- return @service_types.member?(extension_url)
85
+ return @service_types.member?(url)
81
86
  end
82
87
 
83
88
  # Returns the OpenID delegate URL. This is the URL on the OpenID server,
data/lib/openid/stores.rb CHANGED
@@ -7,8 +7,8 @@ module OpenID
7
7
 
8
8
  @@AUTH_KEY_LEN = 20
9
9
 
10
- # Put a Association object into storace
11
- def store_association(association)
10
+ # Put a Association object into storage
11
+ def store_association(server_url, association)
12
12
  raise NotImplementedError
13
13
  end
14
14
 
@@ -16,13 +16,13 @@ module OpenID
16
16
  # the server_url. Returns nil if no such association is found or if
17
17
  # the one matching association is expired. (Is allowed to GC expired
18
18
  # associations when found.)
19
- def get_association(server_url)
19
+ def get_association(server_url, handle=nil)
20
20
  raise NotImplementedError
21
21
  end
22
22
 
23
23
  # If there is a matching association, remove it from the store and
24
24
  # return true, otherwise return false.
25
- def removeAssociation(server_url, handle)
25
+ def remove_association(server_url, handle)
26
26
  raise NotImplementedError
27
27
  end
28
28
 
@@ -59,11 +59,11 @@ module OpenID
59
59
  @auth_key = Digest::SHA1.hexdigest(secret_phrase)
60
60
  end
61
61
 
62
- def store_association(assoc)
62
+ def store_association(server_url, assoc)
63
63
  nil
64
64
  end
65
65
 
66
- def get_association(server_url)
66
+ def get_association(server_url, handle=nil)
67
67
  nil
68
68
  end
69
69
 
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xrds:XRDS
3
+ xmlns:xrds="xri://$xrds"
4
+ xmlns:openid="http://openid.net/xmlns/1.0"
5
+ xmlns="xri://$xrd*($v*2.0)">
6
+ <XRD>
7
+
8
+ <Service priority="0">
9
+ <Type>http://openid.net/signon/1.0</Type>
10
+ <URI>http://www.myopenid.com/server</URI>
11
+ <openid:Delegate>http://brian.myopenid.com/</openid:Delegate>
12
+ </Service>
13
+
14
+ </XRD>
15
+ </xrds:XRDS>
16
+
data/test/runtests.rb CHANGED
@@ -1,5 +1,14 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
+ # the tests exploit some corner cases which generate warning messages
4
+ # on stderr. try and silence those messages to avoid unnecessarily concerning
5
+ # the library user.
6
+ begin
7
+ STDERR.reopen('/dev/null', 'w')
8
+ rescue
9
+ puts "\nPlease ignore the non Test::Unit error messages generated below.\n"
10
+ end
11
+
3
12
  require "teststore"
4
13
  require "assoc"
5
14
  require "dh"
@@ -9,3 +18,4 @@ require "trustroot"
9
18
  require "assoc"
10
19
  require "server2"
11
20
  require "consumer"
21
+ require "service"
data/test/runtests.rb~ ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # the tests exploit some corner cases which generate warning messages
4
+ # on stderr. try and silence those messages to avoid unnecessarily concerning
5
+ # the library user.
6
+ begin
7
+ STDERR.reopen('/dev/null', 'w')
8
+ rescue
9
+ print ''
10
+ end
11
+
12
+ require "teststore"
13
+ require "assoc"
14
+ require "dh"
15
+ require "util"
16
+ require "linkparse"
17
+ require "trustroot"
18
+ require "assoc"
19
+ require "server2"
20
+ require "consumer"
21
+ require "service"