NAME

WebService::GoogleAPI::Client::AuthStorage - Role for classes which store your auth credentials

VERSION

version 0.24_001

SYNOPSIS

  package My::Cool::AuthStorage::Class;
  use Moo;
  with 'WebService::GoogleAPI::Client::AuthStorage';

  ... # implement the necessary functions

  package main;
  use WebService::GoogleAPI::Client;
  use My::Cool::AuthStorage::Class;
  my $gapi = WebService::GoogleAPI::Client->new(
     auth_storage => My::Cool::AuthStorage::Class->new
  );
  ... # and now your class manages the access_tokens

WebService::GoogleAPI::Client::AuthStorage is a Moo::Role for auth storage backends. This dist comes with two consumers, WebService::GoogleAPI::Client::AuthStorage::GapiJSON and WebService::GoogleAPI::Client::AuthStorage::ServiceAccount. See those for more info on how you can use them with WebService::GoogleAPI::Client.

This is a role which defines the interface that WebService::GoogleAPI::Client will use when making requests.

ATTRIBUTES

user

The user that an access token should be returned for. Is read/write. May be falsy, depending on the backend.

ua

An weak reference to the WebService::GoogleAPI::Client::UserAgent that this is attached to, so that access tokens can be refreshed. The UserAgent object manages this.

METHODS

refresh_user_token

Makes the call to Google's OAuth API to refresh a token for a user. Requires one parameter, a hashref with the keys:

client_id Your OAuth Client ID
client_secret Your OAuth Client Secret
refresh_token The refresh token for the user

Will return the token from the API, for the backend to store (wherever it pleases).

Will die with the error message from Google if the refresh fails.

refresh_service_account_token

Makes the call to Google's OAuth API to refresh a token for a service account. Requires one parameter, a Mojo::JWT::Google object already set with the user and scopes requested.

Will return the token from the API, for the backend to store (wherever it pleases).

Will die with the error message from Google if the refresh fails.

REQUIRES

It requires the consuming class to implement functions with the following names:

scopes

A list of scopes that you expect the access token to be valid for. This could be read/write, but it's not necessary. Some backends may have different credentials for different sets of scopes (though as an author, you probably want to just have the whole set you need upfront).

refresh_access_token

A method which will refresh the access token if it has been determined to have expired. Take a look at the two consumers which come with this dist for examples of how to renew user credentials and service account credentials.

get_access_token

A method which will return the access token for the current user and scopes. This method is wrapped to augment whatever has been returned with user and scopes data for introspection by making a WebService::GoogleAPI::Client::AccessToken instance. If you choose to return such an instance yourself, then it will be left alone.

AUTHORS

  • Veesh Goldman <veesh@cpan.org>

  • Peter Scott <localshop@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2017-2021 by Peter Scott and others.

This is free software, licensed under:

  The Apache License, Version 2.0, January 2004