我一直在尝试使用服务帐户的谷歌日历进行身份验证,但运气不佳。以下程序在JSON::使用的WebToken编码调用期间死亡
RSA.xs:178:OpenSSL错误:/usr/local/share/perl/5.14.2/JSON/WebToken/Crypt/RSA.pm第19行的base64解码错误。
当我取出私钥并尝试使用openssl进行验证时,我会遇到类似的错误。那么,谷歌是给了我一个错误的钥匙(我已经仔细检查过了),还是我做错了什么?
#!/usr/bin/perl
use warnings;
use strict;
use JSON;
use JSON::WebToken;
use LWP::UserAgent;
my $private_key_string = "-----BEGIN PRIVATE KEY-----n...n-----END PRIVATE KEY-----n";
my $time = time;
my $jwt = JSON::WebToken->encode(
{
# your service account id here
iss => '...9ve@developer.gserviceaccount.com',
scope => "https://www.google.com/calendar/feeds/",
aud => 'https://accounts.google.com/o/oauth2/token',
exp => $time + 3600,
iat => $time,
# To access the google admin sdk with a service account
# the service account must act on behalf of an account
# that has admin privileges on the domain
# Otherwise the token will be returned but API calls
# will generate a 403
prn => 'me@gmail.com',
},
$private_key_string,
'RS256',
{ typ => 'JWT' }
);
# Now post it to google
my $ua = LWP::UserAgent->new();
my $response = $ua->post(
'https://accounts.google.com/o/oauth2/token',
{ grant_type => encode_entities('urn:ietf:params:oauth:grant-type:jwt-bearer'),
assertion => $jwt
}
);
unless ( $response->is_success() ) {
die( $response->code, "n", $response->content, "n" );
}
我也遇到了同样的问题。当我从Google Developer控制台(\u003d)下载RSA密钥末尾的base64终端时,它已经被JSON编码。只需将其更改为普通的'='即可。
FWIW服务密钥不再受此问题的影响。