X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fstemmaweb%2FAuthentication%2FCredential%2FGoogle.pm;h=056082b784ff2e9f4064e83b2c3c0dba63611d80;hb=82be740cdfb5d03a0de50c3f8d6ec74dbcf692a9;hp=ec8ec8a5a207e6b54c508ef23f541490b3333c57;hpb=b1d9ab02c0b3c923596ebae9d3e2e4c45397c8f7;p=scpubgit%2Fstemmaweb.git diff --git a/lib/stemmaweb/Authentication/Credential/Google.pm b/lib/stemmaweb/Authentication/Credential/Google.pm index ec8ec8a..056082b 100644 --- a/lib/stemmaweb/Authentication/Credential/Google.pm +++ b/lib/stemmaweb/Authentication/Credential/Google.pm @@ -28,8 +28,6 @@ sub new { my ($class, $config, $app, $realm) = @_; $class = ref $class || $class; - warn "MEEP\n\n"; - my $self = { _config => $config, _app => $app, @@ -46,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 @@ -71,48 +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, - active => $user->active, - }); - - 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 @@ -142,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'}->{public_cert_url} || 'https://www.googleapis.com/oauth2/v1/certs' ); return decode_json(get($url)); }