X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fstemmaweb%2FAuthentication%2FCredential%2FGoogle.pm;h=07a3c5ffb1fc49c4d8a9ba71fd7ccbe60ef1700b;hb=fad4df2573e1f42fc93308a05564679b43541d6f;hp=90308aee32876bf917d95f97b761a50b2041abc1;hpb=85990daf0e04461abd1b789fb283848dd583c134;p=scpubgit%2Fstemmaweb.git diff --git a/lib/stemmaweb/Authentication/Credential/Google.pm b/lib/stemmaweb/Authentication/Credential/Google.pm index 90308ae..07a3c5f 100644 --- a/lib/stemmaweb/Authentication/Credential/Google.pm +++ b/lib/stemmaweb/Authentication/Credential/Google.pm @@ -44,24 +44,15 @@ sub authenticate { $id_token ||= $c->req->method eq 'GET' ? $c->req->query_params->{id_token} : $c->req->body_params->{id_token}; - use Data::Dumper; - $c->log->debug(Dumper $authinfo); - if (!$id_token) { Catalyst::Exception->throw("id_token not specified."); } my $userinfo = $self->decode($id_token); - use Data::Dumper; - $c->log->debug(Dumper $userinfo); - my $sub = $userinfo->{sub}; my $openid = $userinfo->{openid_id}; - $c->log->debug($sub); - $c->log->debug($openid); - if (!$sub || !$openid) { Catalyst::Exception->throw( 'Could not retrieve sub and openid from token! Is the token @@ -69,46 +60,7 @@ sub authenticate { ); } - # Do we have a user with the google id already? - my $user = $realm->find_user({ - id => $sub - }); - - if ($user) { - return $user; - } - - # Do we have a user with the openid? - - $user = $realm->find_user({ - url => $openid - }); - - if (!$user) { - throw ("Could not find a user with that openid or sub!"); - } - - my $new_user = $realm->add_user({ - username => $sub, - password => $user->password, - role => $user->role, - }); - - foreach my $t (@{ $user->traditions }) { - $new_user->add_tradition($t); - } - - warn ($new_user->id); - - warn (scalar @{$user->traditions}); - warn (scalar @{$new_user->traditions}); - - use Data::Dumper; - warn (Dumper($user->id)); - - $realm->delete_user({ username => $user->id }); - - return $new_user; + return $realm->find_user($userinfo, $c); } =head1 METHODS @@ -138,7 +90,7 @@ Decoded JSON object containing certificates. sub retrieve_certs { my ($self, $url) = @_; - $url ||= 'https://www.googleapis.com/oauth2/v1/certs'; + $url ||= ( $self->{_app}->config->{'Authentication::Credential::Google'}->{url} || 'https://www.googleapis.com/oauth2/v1/certs' ); return decode_json(get($url)); }