我花了很多时间处理这个问题,但无法找出我做错了什么。
我有一个客户端-服务器 Web 应用程序(客户端中的 javascript,服务器中的节点)。在服务器中,我使用 googleapis。 我希望用户在客户端使用 Google Oauth2 进行身份验证,然后将授权码发送到服务器,获取 access_token(或 refresh_token),然后对 google API 进行一些调用(现在它将创建或删除日历以用户的帐户)。
尝试在后端获取 access_token 时出错。
在前端我有这个电话:
var SCOPE_STRING = "https://www.googleapis.com/auth/calendar.app.created";
if(nouUsuari.hasGrantedScopes(SCOPE_STRING)) {
console.log("hasGrantedScopes.");
} else {
nouUsuari.grantOfflineAccess({
scope: SCOPE_STRING
})
.then(function(resp){
var authCode = resp.code;
//I send here authCode to the backEnd
self.guardarTokens(authCode);
})
}
在后端,我一直在获取我的 acces_token,这个电话是:
var response = await self.oAuth2Client.getToken(authCodeFromFrontEnd)
我总是收到以下错误:
{
"error": "unauthorized_client",
"error_description": "Unauthorized"
}
任何帮助将不胜感激,因为我不知道如何跟进。
非常感谢!!!!