Google API OAuth2 : “invalid_grant” error when requesting token for Service Account with Perl

后端 未结 4 937
后悔当初
后悔当初 2021-01-06 17:52

Got the credentials for Service Account from Developer Console

First, I converted p12 private key to PEM:

openssl pkcs12 -in 

        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-06 18:07

    I don't know why, but the problem was with curl.

    I replaced it by WWW::Mechanize:

    my $mech = WWW::Mechanize->new( autocheck => 1 );
    $mech->post('https://accounts.google.com/o/oauth2/token',
        'Content-Type' => 'application/x-www-form-urlencoded',
        'Content' => [
            'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
            'assertion' => $token_request,
        ],
    );
    

    and it works.

提交回复
热议问题