I have created an nodejs api to generate oauth2 accessToken using google-auth-library for FCM HTTP V1 API.
This api generates an oauth2 accessToken which will then be used by my react app to make a request to FCM HTTP V1 API.
The api code works fine on my local machine gives the excepted output. But when this code is deployed on server I am facing timeout issue for https://www.googleapis.com/oauth2/v4/token this endpoint.
Provide me solution on how can I solve this ....what is the reason for this issue?
Below is my code for generating oauth2 access token:
module.exports.generateToken = async function (transactionId) {
try
{
const SCOPES = [config.MESSAGING_SCOPE];
const currentTimeZone = new Date(Date.now());
currentTimeZone.setHours( currentTimeZone.getHours() + config.AccessTokenExpiryTime );
const auth = new GoogleAuth({
credentials: {
client_email: config.client_email,
private_key: config.private_key,
},
scopes: SCOPES,
});
const client = await auth.getClient();
const accessToken = await client.getAccessToken();
globalaccessToken = accessToken.token;
tokenExpiry = currentTimeZone;
loggerDetail.debug(transactionId + " AccessToken Retrieved Successfully ");
return {
accessTokenValue: globalaccessToken,
tokenExpiration: tokenExpiry,
};
}catch (error) {
loggerDetail.debug( transactionId + " Failed to retrieve access token: " + error.message );
}
};