Catalyst-Plugin-Authentication-Credential-GooglePlus

 view release on metacpan or  search on metacpan

lib/Catalyst/Plugin/Authentication/Credential/GooglePlus.pm  view on Meta::CPAN

package Catalyst::Plugin::Authentication::Credential::GooglePlus;

use Crypt::OpenSSL::X509;
use JSON::WebToken;
use JSON::MaybeXS;
use MIME::Base64;
use LWP::Simple qw(get);
use Date::Parse qw(str2time);
use Try::Tiny;

use strictures 1;

our $VERSION = 0.1;

=head1 NAME

Catalyst::Authentication::Credential::GooglePlus - Authenticates a user using a
Google Plus token.

=head1 SYNOPSIS

'Plugin::Authentication' => {
    default => {
        credential => {
            class           => 'GooglePlus',
            token_field     => 'id_token',
            public_cert_url => 'https://www.googleapis.com/oauth2/v1/certs',
        },
        store => {
            class => 'DBIx::Class',
            user_model => 'DB::User',
            ...
        },
    },
},

=head1 DESCRIPTION

Retrieves Google's public certificates, and then retrieves the key from the
cert using L<Crypt::OpenSSL::X509>. Finally, uses the pubkey to decrypt a
Google token using L<JSON::WebToken>.

See https://github.com/errietta/Catalyst-Plugin-Authentication-Credential-GooglePlus-example
for an example.

=cut

sub new {
    my ($class, $config, $app, $realm) = @_;
    $class = ref $class || $class;

    my $self = {
        %{ $config },
        %{ $realm->{config} },
        _app => $app,
        _realm => $realm,
    };

    # Google names it id_token
    $self->{token_field} ||= "id_token";

    bless $self, $class;
}

=head1 METHODS

=head2 authenticate

Retrieves a JSON web token from either $authinfo, or GET or POST query



( run in 0.613 second using v1.01-cache-2.11-cpan-39bf76dae61 )