Skip to content

Commit

Permalink
An invalid identity url passed through authenticate_with_open_id will…
Browse files Browse the repository at this point in the history
… no longer raise an InvalidOpenId exception. Instead it will return Result[:missing] to the completion block.
  • Loading branch information
josh committed Apr 18, 2008
1 parent c5f60a4 commit 8a0758c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* An invalid identity url passed through authenticate_with_open_id will no longer raise an InvalidOpenId exception. Instead it will return Result[:missing] to the completion block.

* Allow a return_to option to be used instead of the requested url [Josh Peek]

* Updated plugin to use Ruby OpenID 2.x.x [Josh Peek]
Expand Down
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ You can support it in your app by changing #open_id_authentication
case result.status
when :missing
failed_login "Sorry, the OpenID server couldn't be found"
when :invalid
failed_login "Sorry, but this does not appear to be a valid OpenID"
when :canceled
failed_login "OpenID verification was canceled"
when :failed
Expand Down
6 changes: 5 additions & 1 deletion lib/open_id_authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class InvalidOpenId < StandardError
class Result
ERROR_MESSAGES = {
:missing => "Sorry, the OpenID server couldn't be found",
:invalid => "Sorry, but this does not appear to be a valid OpenID",
:canceled => "OpenID verification was canceled",
:failed => "OpenID verification failed",
:setup_needed => "OpenID verification needs setup"
Expand Down Expand Up @@ -79,18 +80,21 @@ def using_open_id?(identity_url = params[:openid_url]) #:doc:

def authenticate_with_open_id(identity_url = params[:openid_url], options = {}, &block) #:doc:
if params[:open_id_complete].nil?
begin_open_id_authentication(normalize_url(identity_url), options, &block)
begin_open_id_authentication(identity_url, options, &block)
else
complete_open_id_authentication(&block)
end
end

private
def begin_open_id_authentication(identity_url, options = {})
identity_url = normalize_url(identity_url)
return_to = options.delete(:return_to)
open_id_request = open_id_consumer.begin(identity_url)
add_simple_registration_fields(open_id_request, options)
redirect_to(open_id_redirect_url(open_id_request, return_to))
rescue OpenIdAuthentication::InvalidOpenId => e
yield Result[:invalid], identity_url, nil
rescue OpenID::OpenIDError, Timeout::Error => e
logger.error("[OPENID] #{e}")
yield Result[:missing], identity_url, nil
Expand Down
7 changes: 7 additions & 0 deletions test/open_id_authentication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def test_authentication_should_fail_when_the_identity_server_is_missing
end
end

def test_authentication_should_be_invalid_when_the_identity_url_is_invalid
@controller.send(:authenticate_with_open_id, "!") do |result, identity_url|
assert result.invalid?, "Result expected to be invalid but was not"
assert_equal "Sorry, but this does not appear to be a valid OpenID", result.message
end
end

def test_authentication_should_fail_when_the_identity_server_times_out
open_id_consumer = mock()
open_id_consumer.expects(:begin).raises(Timeout::Error, "Identity Server took too long.")
Expand Down

0 comments on commit 8a0758c

Please sign in to comment.