Perl6 OAuth2 Client for Google
Perl6
Latest commit aa0dedb Oct 26, 2016 @bduggan committed on GitHub Merge pull request #1 from zoffixznet/patch-1
Add mandatory "perl" META field
Permalink
Failed to load latest commit information.
eg verify-id Jul 28, 2016
lib/OAuth2/Client comment format Aug 9, 2016
t scope Jul 28, 2016
.gitignore gitignore Jul 27, 2016
.travis.yml travis, meta Jul 28, 2016
LICENSE license and example Jul 28, 2016
META.info fixed meta Aug 9, 2016
META.json Add mandatory "perl" META field Oct 26, 2016
README.md syntax highlighting Jul 29, 2016
id.p6 fixed meta Aug 9, 2016

README.md

OAuth2::Client::Google

Authenticate with Google using OAuth2.

Build Status

For details see https://developers.google.com/identity/protocols/OAuth2WebServer.

Quick How-to

  1. Go to http://console.developers.google.com and create a project.

  2. Set up credentials for a web server and set your redirect URIs.

  3. Download the JSON file (client_id.json).

  4. In your application, create an oauth2 object like this:

 my $oauth = OAuth2::Client::Google.new(
    config => from-json('./client_id.json'.IO.slurp),
    redirect-uri => 'http://localhost:3334/oauth',
    scope => 'email'
 );

where redirect-uri is one of your redirect URIs and scope is a space or comma-separated list of scopes from https://developers.google.com/identity/protocols/googlescopes.

To authenticate, redirect the user to

$oauth.auth-uri

Then when they come back and send a request to '/oauth', grab the "code" parameter from the query string. Use it to call

my $token = $oauth.code-to-token(code => $code)

This will give you $token<access_token>, which you can then use with google APIs.

If you also included "email" in the scope, you will get id-token, which you can use like this:

my $identity = $oauth.verify-id(id-token => $token<id_token>)

which has, e.g. $identity<email> and $identity<given_name>.

For a working example, see eg/get-calendar-data.p6.

TODO

  • Better documentation
  • Refresh tokens