Tie-Google-Sheets
view release on metacpan or search on metacpan
lib/Tie/Google/Sheets/Client.pm view on Meta::CPAN
my $sa = $self->service_account;
my $now = time();
my $jwt = encode_jwt(
payload => {
iss => $sa->{client_email},
scope => SCOPE,
aud => $sa->{token_uri} // TOKEN_URI,
iat => $now,
exp => $now + 3600,
},
key => \$sa->{private_key},
alg => 'RS256',
);
my $body = join '&',
'grant_type=' . uri_escape('urn:ietf:params:oauth:grant-type:jwt-bearer'),
'assertion=' . uri_escape($jwt);
my $res = $self->ua->request( 'POST', $sa->{token_uri} // TOKEN_URI, {
headers => { 'content-type' => 'application/x-www-form-urlencoded' },
content => $body,
t/service_account_auth.t view on Meta::CPAN
my $rsa = Crypt::PK::RSA->new->generate_key(256);
my $private_pem = $rsa->export_key_pem('private');
my $public_pem = $rsa->export_key_pem('public');
my $mock = Local::FakeSheetsUA->new;
tie my %doc, 'Tie::Google::Sheets',
spreadsheet_id => 'test-spreadsheet',
any_ua => $mock,
service_account => {
client_email => 'fake@example.iam.gserviceaccount.com',
private_key => $private_pem,
};
$doc{Sheet1}{A1} = 'hi';
my @calls = $mock->calls;
is scalar(@calls), 3, 'a token request, an existence check, and an API request were made';
my $token_call = $calls[0];
is $token_call->{url}, 'https://oauth2.googleapis.com/token', 'first call is the token endpoint';
( run in 1.236 second using v1.01-cache-2.11-cpan-8379b9b8ec2 )