From 5897d3419cd61a2de633db3f271586043e98ad52 Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Wed, 26 Mar 2014 14:52:50 +1100
Subject: [PATCH] BUGFIX: identity_url was not fished out correctly

If I user logged in with Google and then changed email,
they would no longer be able to log in with google
---
 lib/auth/open_id_authenticator.rb                  | 7 ++++---
 spec/components/auth/open_id_authenticator_spec.rb | 3 ++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/auth/open_id_authenticator.rb b/lib/auth/open_id_authenticator.rb
index 435a313ce..b0eb80658 100644
--- a/lib/auth/open_id_authenticator.rb
+++ b/lib/auth/open_id_authenticator.rb
@@ -13,12 +13,12 @@ class Auth::OpenIdAuthenticator < Auth::Authenticator
     result = Auth::Result.new
 
     data = auth_token[:info]
-    identity_url = auth_token[:extra][:identity_url]
+    identity_url = auth_token[:extra][:response].identity_url
     result.email = email = data[:email]
 
     # If the auth supplies a name / username, use those. Otherwise start with email.
-    result.name = name = data[:name] || data[:email]
-    result.username = username = data[:nickname] || data[:email]
+    result.name = data[:name] || data[:email]
+    result.username = data[:nickname] || data[:email]
 
     user_open_id = UserOpenId.find_by_url(identity_url)
 
@@ -32,6 +32,7 @@ class Auth::OpenIdAuthenticator < Auth::Authenticator
       # note email may change by the time after_create_account runs
       email: email
     }
+
     result.email_valid = @opts[:trusted]
 
     result
diff --git a/spec/components/auth/open_id_authenticator_spec.rb b/spec/components/auth/open_id_authenticator_spec.rb
index 5c96cc6ca..9f2158d87 100644
--- a/spec/components/auth/open_id_authenticator_spec.rb
+++ b/spec/components/auth/open_id_authenticator_spec.rb
@@ -12,7 +12,8 @@ describe Auth::OpenIdAuthenticator do
     auth = Auth::OpenIdAuthenticator.new("test", "id", trusted: true)
 
     user = Fabricate(:user)
-    result = auth.after_authenticate(info: {email: user.email}, extra: {identity_url: 'abc'})
+    response = OpenStruct.new(identity_url: 'abc')
+    result = auth.after_authenticate(info: {email: user.email}, extra: {response: response})
     result.user.should == user
   end
 end