Pass email along.
Errietta Kostala [Wed, 4 Feb 2015 14:34:04 +0000 (14:34 +0000)]
lib/Text/Tradition/Directory.pm
lib/stemmaweb/Authentication/Credential/Google.pm
t/07google.t

index cb20c97..1727903 100644 (file)
@@ -545,6 +545,7 @@ sub _find_gplus {
 
     my $sub = $userinfo->{sub};
     my $openid = $userinfo->{openid_id};
+    my $email = $userinfo->{email};
 
     # Do we have a user with the google id already?
 
@@ -567,12 +568,13 @@ sub _find_gplus {
     }
 
     my $new_user = $self->add_user({
-            username => $sub,
-            password => $user->password,
-            role     => $user->role,
-            active   => $user->active,
-            sub      => $sub,
+            username  => $sub,
+            password  => $user->password,
+            role      => $user->role,
+            active    => $user->active,
+            sub       => $sub,
             openid_id => $openid,
+            email     => $email,
         });
 
     foreach my $t (@{ $user->traditions }) {
index 5a7e3d8..32f22c9 100644 (file)
@@ -48,11 +48,17 @@ sub authenticate {
         Catalyst::Exception->throw("id_token not specified.");
     }
 
+    my $email = $authinfo->{email};
+    $email ||= $c->req->method eq 'GET' ? $c->req->query_params->{email} :
+    $c->req->body_params->{email};
+
     my $userinfo = $self->decode($id_token);
 
     my $sub = $userinfo->{sub};
     my $openid = $userinfo->{openid_id};
 
+    $userinfo->{email} = $email if $email;
+
     if (!$sub || !$openid) {
         Catalyst::Exception->throw(
             'Could not retrieve sub and openid from token! Is the token
index 7816957..09a2c65 100644 (file)
@@ -199,7 +199,7 @@ io("$FindBin::Bin/var")->rmtree if io("$FindBin::Bin/var")->exists;
 
     $ua->get('/');
 
-    $ua->content_contains('Hello! 4242!', 'We are logged in.');
+    $ua->content_contains('Hello! email@example.org!', 'We are logged in.');
 
     ok $dir->find_user({ sub => 4242, openid_id => 'https://www.google.com/accounts/o8/id3' }), 'The G+ user is there.';
 
@@ -219,7 +219,7 @@ io("$FindBin::Bin/var")->rmtree if io("$FindBin::Bin/var")->exists;
 
     $ua->get('/');
 
-    $ua->content_contains('Hello! 4242!', 'We are logged in.');
+    $ua->content_contains('Hello! email@example.org!', 'We ar logged in.');
 }
 
 io("$FindBin::Bin/var")->rmtree if io("$FindBin::Bin/var")->exists;