<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>db/migrate/015_upgrade_open_id_authentication_tables.rb</filename>
    </added>
    <added>
      <filename>vendor/plugins/open_id_authentication/generators/open_id_authentication_tables/open_id_authentication_tables_generator.rb</filename>
    </added>
    <added>
      <filename>vendor/plugins/open_id_authentication/generators/open_id_authentication_tables/templates/migration.rb</filename>
    </added>
    <added>
      <filename>vendor/plugins/open_id_authentication/generators/upgrade_open_id_authentication_tables/templates/migration.rb</filename>
    </added>
    <added>
      <filename>vendor/plugins/open_id_authentication/generators/upgrade_open_id_authentication_tables/upgrade_open_id_authentication_tables_generator.rb</filename>
    </added>
    <added>
      <filename>vendor/plugins/open_id_authentication/test/test_helper.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -9,7 +9,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version =&gt; 14) do
+ActiveRecord::Schema.define(:version =&gt; 15) do
 
   create_table &quot;attachments&quot;, :force =&gt; true do |t|
     t.integer  &quot;size&quot;
@@ -51,13 +51,9 @@ ActiveRecord::Schema.define(:version =&gt; 14) do
   end
 
   create_table &quot;open_id_authentication_nonces&quot;, :force =&gt; true do |t|
-    t.string  &quot;nonce&quot;
-    t.integer &quot;created&quot;
-  end
-
-  create_table &quot;open_id_authentication_settings&quot;, :force =&gt; true do |t|
-    t.string &quot;setting&quot;
-    t.binary &quot;value&quot;
+    t.integer &quot;timestamp&quot;,  :null =&gt; false
+    t.string  &quot;server_url&quot;
+    t.string  &quot;salt&quot;,       :null =&gt; false
   end
 
   create_table &quot;page_versions&quot;, :force =&gt; true do |t|</diff>
      <filename>db/schema.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,7 @@
+* Updated plugin to use Ruby OpenID 2.x.x [Josh Peek]
+
+* Tied plugin to ruby-openid 1.1.4 gem until we can make it compatible with 2.x [DHH]
+
 * Use URI instead of regexps to normalize the URL and gain free, better matching #8136 [dkubb]
 
 * Allow -'s in #normalize_url [Rick]</diff>
      <filename>vendor/plugins/open_id_authentication/CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,7 @@ Provides a thin wrapper around the excellent ruby-openid gem from JanRan. Be sur
 To understand what OpenID is about and how it works, it helps to read the documentation for lib/openid/consumer.rb
 from that gem.
 
-The specification used is http://openid.net/specs/openid-authentication-1_1.html (not the 2.0 draft).
+The specification used is http://openid.net/specs/openid-authentication-2_0.html.
 
 
 Prerequisites
@@ -95,7 +95,7 @@ app/controllers/sessions_controller.rb
             if @current_user = @account.users.find_by_identity_url(identity_url)
               successful_login
             else
-              failed_login &quot;Sorry, no user by that identity URL exists (#{identity_url})&quot;)
+              failed_login &quot;Sorry, no user by that identity URL exists (#{identity_url})&quot;
             end
           else
             failed_login result.message</diff>
      <filename>vendor/plugins/open_id_authentication/README</filename>
    </modified>
    <modified>
      <diff>@@ -1,12 +1,11 @@
 begin
-  require 'openid'  
+  require 'openid'
 rescue LoadError
   begin
-    gem 'ruby-openid'
-    require 'openid'
-  rescue LoadError
+    gem 'ruby-openid', '&gt;=2.0.4'
+  rescue Gem::LoadError
     puts &quot;Install the ruby-openid gem to enable OpenID support&quot;
   end
 end
 
-ActionController::Base.send :include, OpenIdAuthentication
\ No newline at end of file
+ActionController::Base.send :include, OpenIdAuthentication</diff>
      <filename>vendor/plugins/open_id_authentication/init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,16 +1,20 @@
+require 'uri'
+require 'openid/extensions/sreg'
+require 'openid/store/filesystem'
+
 module OpenIdAuthentication
   OPEN_ID_AUTHENTICATION_DIR = RAILS_ROOT + &quot;/tmp/openids&quot;
-  
+
   def self.store
     @@store
   end
-  
+
   def self.store=(value)
     @@store = value
   end
-  
+
   self.store = :db
-  
+
   def store
     OpenIdAuthentication.store
   end
@@ -20,19 +24,20 @@ module OpenIdAuthentication
 
   class Result
     ERROR_MESSAGES = {
-      :missing    =&gt; &quot;Sorry, the OpenID server couldn't be found&quot;,
-      :canceled   =&gt; &quot;OpenID verification was canceled&quot;,
-      :failed     =&gt; &quot;Sorry, the OpenID verification failed&quot;
+      :missing      =&gt; &quot;Sorry, the OpenID server couldn't be found&quot;,
+      :canceled     =&gt; &quot;OpenID verification was canceled&quot;,
+      :failed       =&gt; &quot;Sorry, the OpenID verification failed&quot;,
+      :setup_needed =&gt; &quot;OpenID verification needs setup&quot;
     }
-    
+
     def self.[](code)
       new(code)
     end
-    
+
     def initialize(code)
       @code = code
     end
-    
+
     def ===(code)
       if code == :unsuccessful &amp;&amp; unsuccessful?
         true
@@ -40,7 +45,7 @@ module OpenIdAuthentication
         @code == code
       end
     end
-    
+
     ERROR_MESSAGES.keys.each { |state| define_method(&quot;#{state}?&quot;) { @code == state } }
 
     def successful?
@@ -50,24 +55,21 @@ module OpenIdAuthentication
     def unsuccessful?
       ERROR_MESSAGES.keys.include?(@code)
     end
-    
+
     def message
       ERROR_MESSAGES[@code]
     end
   end
 
   def self.normalize_url(url)
-    begin
-      uri = URI.parse(url)
-      uri = URI.parse(&quot;http://#{uri}&quot;) unless uri.scheme
-      uri.scheme = uri.scheme.downcase  # URI should do this
-      uri.normalize.to_s
-    rescue URI::InvalidURIError
-      raise InvalidOpenId.new(&quot;#{url} is not an OpenID URL&quot;)
-    end
+    uri = URI.parse(url.to_s.strip)
+    uri = URI.parse(&quot;http://#{uri}&quot;) unless uri.scheme
+    uri.scheme = uri.scheme.downcase  # URI should do this
+    uri.normalize.to_s
+  rescue URI::InvalidURIError
+    raise InvalidOpenId.new(&quot;#{url} is not an OpenID URL&quot;)
   end
 
-
   protected
     def normalize_url(url)
       OpenIdAuthentication.normalize_url(url)
@@ -87,59 +89,63 @@ module OpenIdAuthentication
       end
     end
 
-
   private
     def begin_open_id_authentication(identity_url, fields = {})
-      open_id_response = timeout_protection_from_identity_server { open_id_consumer.begin(identity_url) }
-
-      case open_id_response.status
-      when OpenID::FAILURE
-        yield Result[:missing], identity_url, nil
-      when OpenID::SUCCESS
-        add_simple_registration_fields(open_id_response, fields)
-        redirect_to(open_id_redirect_url(open_id_response))
-      end
+      open_id_request = open_id_consumer.begin(identity_url)
+      add_simple_registration_fields(open_id_request, fields)
+      redirect_to(open_id_redirect_url(open_id_request))
+    rescue OpenID::OpenIDError, Timeout::Error =&gt; e
+      logger.error(&quot;[OPENID] #{e}&quot;)
+      yield Result[:missing], identity_url, nil
     end
-  
+
     def complete_open_id_authentication
-      open_id_response = timeout_protection_from_identity_server { open_id_consumer.complete(params) }
-      identity_url     = normalize_url(open_id_response.identity_url) if open_id_response.identity_url
+      params_with_path = params.reject { |key, value| request.path_parameters[key] }
+      open_id_response = timeout_protection_from_identity_server { open_id_consumer.complete(params_with_path, requested_url) }
+      identity_url     = normalize_url(open_id_response.endpoint.claimed_id) if open_id_response.endpoint.claimed_id
 
       case open_id_response.status
-      when OpenID::CANCEL
+      when OpenID::Consumer::SUCCESS
+        yield Result[:successful], identity_url, OpenID::SReg::Response.from_success_response(open_id_response)
+      when OpenID::Consumer::CANCEL
         yield Result[:canceled], identity_url, nil
-      when OpenID::FAILURE
-        logger.info &quot;OpenID authentication failed: #{open_id_response.msg}&quot;
+      when OpenID::Consumer::FAILURE
         yield Result[:failed], identity_url, nil
-      when OpenID::SUCCESS
-        yield Result[:successful], identity_url, open_id_response.extension_response('sreg')
-      end      
+      when OpenID::Consumer::SETUP_NEEDED
+        yield Result[:setup_needed], open_id_response.setup_url, nil
+      end
     end
 
     def open_id_consumer
       OpenID::Consumer.new(session, open_id_store)
     end
-    
+
     def open_id_store
       case store
-      when :db  : OpenIdAuthentication::DbStore.new
-      when :file: OpenID::FilesystemStore.new(OPEN_ID_AUTHENTICATION_DIR)
+      when :db
+        OpenIdAuthentication::DbStore.new
+      when :file
+        OpenID::FilesystemStore.new(OPEN_ID_AUTHENTICATION_DIR)
       else
         raise &quot;Unknown store: #{store}&quot;
       end
     end
 
+    def add_simple_registration_fields(open_id_request, fields)
+      sreg_request = OpenID::SReg::Request.new
+      sreg_request.request_fields(Array(fields[:required]).map(&amp;:to_s), true) if fields[:required]
+      sreg_request.request_fields(Array(fields[:optional]).map(&amp;:to_s), false) if fields[:optional]
+      sreg_request.policy_url = fields[:policy_url] if fields[:policy_url]
+      open_id_request.add_extension(sreg_request)
+    end
 
-    def add_simple_registration_fields(open_id_response, fields)
-      open_id_response.add_extension_arg('sreg', 'required', [ fields[:required] ].flatten * ',') if fields[:required]
-      open_id_response.add_extension_arg('sreg', 'optional', [ fields[:optional] ].flatten * ',') if fields[:optional]
+    def open_id_redirect_url(open_id_request)
+      open_id_request.return_to_args['open_id_complete'] = '1'
+      open_id_request.redirect_url(root_url, requested_url)
     end
-    
-    def open_id_redirect_url(open_id_response)
-      open_id_response.redirect_url(
-        request.protocol + request.host_with_port + &quot;/&quot;,
-        open_id_response.return_to(&quot;#{request.protocol + request.host_with_port + request.relative_url_root + request.path}?open_id_complete=1&quot;)
-      )     
+
+    def requested_url
+      &quot;#{request.protocol + request.host_with_port + request.relative_url_root + request.path}&quot;
     end
 
     def timeout_protection_from_identity_server
@@ -149,10 +155,10 @@ module OpenIdAuthentication
         def status
           OpenID::FAILURE
         end
-        
+
         def msg
           &quot;Identity server timed out&quot;
         end
       end.new
     end
-end
\ No newline at end of file
+end</diff>
      <filename>vendor/plugins/open_id_authentication/lib/open_id_authentication.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,4 +6,4 @@ module OpenIdAuthentication
       OpenID::Association.new(handle, secret, issued, lifetime, assoc_type)
     end
   end
-end
\ No newline at end of file
+end</diff>
      <filename>vendor/plugins/open_id_authentication/lib/open_id_authentication/association.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,29 +1,19 @@
+require 'openid/store/interface'
+
 module OpenIdAuthentication
-  class DbStore &lt; OpenID::Store
-    def self.gc
+  class DbStore &lt; OpenID::Store::Interface
+    def self.cleanup_nonces
       now = Time.now.to_i
-
-      # remove old nonces
-      nonces = Nonce.find(:all)
-      nonces.each {|n| n.destroy if now - n.created &gt; 6.hours} unless nonces.nil?
-    
-      # remove expired assocs
-      assocs = Association.find(:all)
-      assocs.each { |a| a.destroy if a.from_record.expired? } unless assocs.nil?
+      Nonce.delete_all([&quot;timestamp &gt; ? OR timestamp &lt; ?&quot;, now + OpenID::Nonce.skew, now - OpenID::Nonce.skew])
     end
 
-
-    def get_auth_key
-      unless setting = Setting.find_by_setting('auth_key')
-        auth_key = OpenID::Util.random_string(20)
-        setting  = Setting.create(:setting =&gt; 'auth_key', :value =&gt; auth_key)
-      end
-
-      setting.value
+    def self.cleanup_associations
+      now = Time.now.to_i
+      Association.delete_all(['issued + lifetime &gt; ?',now])
     end
 
     def store_association(server_url, assoc)
-      remove_association(server_url, assoc.handle)    
+      remove_association(server_url, assoc.handle)
       Association.create(:server_url =&gt; server_url,
                          :handle     =&gt; assoc.handle,
                          :secret     =&gt; assoc.secret,
@@ -32,49 +22,34 @@ module OpenIdAuthentication
                          :assoc_type =&gt; assoc.assoc_type)
     end
 
-    def get_association(server_url, handle=nil)
-      assocs = handle.blank? ? 
-        Association.find_all_by_server_url(server_url) :
+    def get_association(server_url, handle = nil)
+      assocs = if handle.blank?
+          Association.find_all_by_server_url(server_url)
+        else
           Association.find_all_by_server_url_and_handle(server_url, handle)
-    
+        end
+
       assocs.reverse.each do |assoc|
-        a = assoc.from_record    
-        if a.expired?
+        a = assoc.from_record
+        if a.expires_in == 0
           assoc.destroy
         else
           return a
         end
       end if assocs.any?
-    
+
       return nil
     end
-  
+
     def remove_association(server_url, handle)
-      assoc = Association.find_by_server_url_and_handle(server_url, handle)
-      unless assoc.nil?
-        assoc.destroy
-        return true
-      end
-      false
-    end
-  
-    def store_nonce(nonce)
-      use_nonce(nonce)
-      Nonce.create :nonce =&gt; nonce, :created =&gt; Time.now.to_i
+      Association.delete_all(['server_url = ? AND handle = ?', server_url, handle]) &gt; 0
     end
-  
-    def use_nonce(nonce)
-      nonce = Nonce.find_by_nonce(nonce)
-      return false if nonce.nil?
-    
-      age = Time.now.to_i - nonce.created
-      nonce.destroy
 
-      age &lt; 6.hours # max nonce age of 6 hours
-    end
-  
-    def dumb?
-      false
+    def use_nonce(server_url, timestamp, salt)
+      return false if Nonce.find_by_server_url_and_timestamp_and_salt(server_url, timestamp, salt)
+      return false if (timestamp - Time.now.to_i).abs &gt; OpenID::Nonce.skew
+      Nonce.create(:server_url =&gt; server_url, :timestamp =&gt; timestamp, :salt =&gt; salt)
+      return true
     end
   end
-end
\ No newline at end of file
+end</diff>
      <filename>vendor/plugins/open_id_authentication/lib/open_id_authentication/db_store.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,4 +2,4 @@ module OpenIdAuthentication
   class Nonce &lt; ActiveRecord::Base
     set_table_name :open_id_authentication_nonces
   end
-end
\ No newline at end of file
+end</diff>
      <filename>vendor/plugins/open_id_authentication/lib/open_id_authentication/nonce.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,15 +2,29 @@ namespace :open_id_authentication do
   namespace :db do
     desc &quot;Creates authentication tables for use with OpenIdAuthentication&quot;
     task :create =&gt; :environment do
-      raise &quot;Task unavailable to this database (no migration support)&quot; unless ActiveRecord::Base.connection.supports_migrations?
+      generate_migration([&quot;open_id_authentication_tables&quot;, &quot;add_open_id_authentication_tables&quot;])
+    end
+
+    desc &quot;Upgrade authentication tables from ruby-openid 1.x.x to 2.x.x&quot;
+    task :upgrade =&gt; :environment do
+      generate_migration([&quot;upgrade_open_id_authentication_tables&quot;, &quot;upgrade_open_id_authentication_tables&quot;])
+    end
+
+    def generate_migration(args)
       require 'rails_generator'
       require 'rails_generator/scripts/generate'
-      Rails::Generator::Scripts::Generate.new.run([ &quot;open_id_authentication_tables&quot;, &quot;add_open_id_authentication_tables&quot; ])
+
+      if ActiveRecord::Base.connection.supports_migrations?
+        Rails::Generator::Scripts::Generate.new.run(args)
+      else
+        raise &quot;Task unavailable to this database (no migration support)&quot;
+      end
     end
 
     desc &quot;Clear the authentication tables&quot;
     task :clear =&gt; :environment do
-      OpenIdAuthentication::DbStore.gc
+      OpenIdAuthentication::DbStore.cleanup_nonces
+      OpenIdAuthentication::DbStore.cleanup_associations
     end
   end
-end
\ No newline at end of file
+end</diff>
      <filename>vendor/plugins/open_id_authentication/tasks/open_id_authentication_tasks.rake</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,4 @@
-require 'test/unit'
-require 'rubygems'
-require 'active_support'
-
-RAILS_ROOT = File.dirname(__FILE__)
-require File.dirname(__FILE__) + &quot;/../lib/open_id_authentication&quot;
+require File.dirname(__FILE__) + '/test_helper'
 
 class NormalizeTest &lt; Test::Unit::TestCase
   include OpenIdAuthentication
@@ -20,7 +15,8 @@ class NormalizeTest &lt; Test::Unit::TestCase
     &quot;https://loudthinking.com:443&quot;          =&gt; &quot;https://loudthinking.com/&quot;,
     &quot;http://loudthinking.com:8080&quot;          =&gt; &quot;http://loudthinking.com:8080/&quot;,
     &quot;techno-weenie.net&quot;                     =&gt; &quot;http://techno-weenie.net/&quot;,
-    &quot;http://techno-weenie.net&quot;              =&gt; &quot;http://techno-weenie.net/&quot;
+    &quot;http://techno-weenie.net&quot;              =&gt; &quot;http://techno-weenie.net/&quot;,
+    &quot;http://techno-weenie.net  &quot;            =&gt; &quot;http://techno-weenie.net/&quot;
   }
 
   def test_normalizations
@@ -30,6 +26,7 @@ class NormalizeTest &lt; Test::Unit::TestCase
   end
   
   def test_broken_open_id
+    assert_raises(InvalidOpenId) { normalize_url(nil) }
     assert_raises(InvalidOpenId) { normalize_url(&quot;=name&quot;) }
   end
-end
\ No newline at end of file
+end</diff>
      <filename>vendor/plugins/open_id_authentication/test/normalize_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,14 +1,4 @@
-require 'test/unit'
-
-require 'rubygems'
-gem 'mocha'
-require 'mocha'
-
-gem 'ruby-openid'
-require 'openid'
-
-RAILS_ROOT = File.dirname(__FILE__)
-require File.dirname(__FILE__) + &quot;/../lib/open_id_authentication&quot;
+require File.dirname(__FILE__) + '/test_helper'
 
 class OpenIdAuthenticationTest &lt; Test::Unit::TestCase
   def setup
@@ -19,8 +9,10 @@ class OpenIdAuthenticationTest &lt; Test::Unit::TestCase
   end
 
   def test_authentication_should_fail_when_the_identity_server_is_missing
-    @controller.stubs(:open_id_consumer).returns(stub(:begin =&gt; stub(:status =&gt; OpenID::FAILURE)))
-    
+    open_id_consumer = mock()
+    open_id_consumer.expects(:begin).raises(OpenID::OpenIDError)
+    @controller.stubs(:open_id_consumer).returns(open_id_consumer)
+
     @controller.send(:authenticate_with_open_id, &quot;http://someone.example.com&quot;) do |result, identity_url|
       assert result.missing?
       assert_equal &quot;Sorry, the OpenID server couldn't be found&quot;, result.message
@@ -28,7 +20,9 @@ class OpenIdAuthenticationTest &lt; Test::Unit::TestCase
   end
 
   def test_authentication_should_fail_when_the_identity_server_times_out
-    @controller.stubs(:open_id_consumer).returns(stub(:begin =&gt; Proc.new { raise Timeout::Error, &quot;Identity Server took too long.&quot; }))
+    open_id_consumer = mock()
+    open_id_consumer.expects(:begin).raises(Timeout::Error, &quot;Identity Server took too long.&quot;)
+    @controller.stubs(:open_id_consumer).returns(open_id_consumer)
 
     @controller.send(:authenticate_with_open_id, &quot;http://someone.example.com&quot;) do |result, identity_url|
       assert result.missing?
@@ -37,8 +31,8 @@ class OpenIdAuthenticationTest &lt; Test::Unit::TestCase
   end
 
   def test_authentication_should_begin_when_the_identity_server_is_present
-    @controller.stubs(:open_id_consumer).returns(stub(:begin =&gt; stub(:status =&gt; OpenID::SUCCESS)))
-    @controller.expects(:begin_open_id_authentication) 
+    @controller.stubs(:open_id_consumer).returns(stub(:begin =&gt; true))
+    @controller.expects(:begin_open_id_authentication)
     @controller.send(:authenticate_with_open_id, &quot;http://someone.example.com&quot;)
   end
-end
\ No newline at end of file
+end</diff>
      <filename>vendor/plugins/open_id_authentication/test/open_id_authentication_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,4 @@
-require 'test/unit'
-
-RAILS_ROOT = File.dirname(__FILE__)
-require File.dirname(__FILE__) + &quot;/../lib/open_id_authentication&quot;
+require File.dirname(__FILE__) + '/test_helper'
 
 class StatusTest &lt; Test::Unit::TestCase
   include OpenIdAuthentication</diff>
      <filename>vendor/plugins/open_id_authentication/test/status_test.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>vendor/plugins/open_id_authentication/lib/generators/open_id_authentication_tables/open_id_authentication_tables_generator.rb</filename>
    </removed>
    <removed>
      <filename>vendor/plugins/open_id_authentication/lib/generators/open_id_authentication_tables/templates/migration.rb</filename>
    </removed>
    <removed>
      <filename>vendor/plugins/open_id_authentication/lib/open_id_authentication/setting.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>be2ffa0157392387109bb638979198be5dd16abe</id>
    </parent>
  </parents>
  <author>
    <name>Josh Owens</name>
    <email>joshua.owens@gmail.com</email>
  </author>
  <url>http://github.com/queso/signal-wiki/commit/cc9cebc43a91094c72ae9e6a4538034dc56d3808</url>
  <id>cc9cebc43a91094c72ae9e6a4538034dc56d3808</id>
  <committed-date>2008-03-31T00:23:36-07:00</committed-date>
  <authored-date>2008-03-31T00:23:36-07:00</authored-date>
  <message>Adding the new openid plugin and migrations to support it.</message>
  <tree>636130fd5c9a9be015c5ab4d09855a80e52a89d2</tree>
  <committer>
    <name>Josh Owens</name>
    <email>joshua.owens@gmail.com</email>
  </committer>
</commit>
