Below is how I am generating the signed JWT .I have created a service account in Google cloud platform console and using its credentials.
const sig = jwt.sign({
"iss":"[email protected]",
"scope":"https://www.googleapis.com/auth/business.manage",
"aud":"https://oauth2.googleapis.com/token",
"iat":Math.floor(Date.now() / 1000),
"exp":Math.floor(Date.now() / 1000) + (60 * 60)
},
key.private_key,
{algorithm: 'RS256'}
);
I am making a post request using the JWT to request access_token this way
var data = querystring.stringify({
grant_type : 'urn:ietf:params:oauth:grant-type:jwt-bearer',
assertion : sig
});
const options = {
url : 'https://oauth2.googleapis.com/token',
headers : {
'Content-Type': 'application/x-www-form-urlencoded'
},
form : data
};
request.post(options, function(error,response,body){
if(error){
console.log("Post Error : ",error);
}
console.log("Body : ",body);
});
I can see the access_token generated OUTPUT OF body :
Body : {
access_token:
'ya29.c.Kp0B6AfFvBqcKU6Jpo_AX7BiwO0ihmjNltLGDvIJl-Lt1K6rZ8VMhrego635lK3er-BDPmnvIoGJMkbpQaNRLRhDsslWvyLt_zDmMeNCPxUsdH1E2-Vn--myztfTq5uZlhsQfxEWSszy0n5tMlnnB56odxH-mcrlrvi2pxFp4soOB6K-aVdM_yWnO_iyor9WLc0Mme6szRgFmd2qTATMeA',
expires_in: 3599,
token_type: 'Bearer'
}
But whenever I use this access_token to access Google My Business API. It gives the error
{ error:
{
code: 404,
message: 'Requested entity was not found.',
status: 'NOT_FOUND'
}
}
Can anyone please help me out to figure out where am I going wrong ? Thanks.