问题描述
我正面临这个错误 |错误:'{"error":"invalid_client"}'|使用 nodejs 使用 Apple API 调用 signIn 时。我已经尝试了很多次,但我遇到了同样的错误。我尝试了不同的代码、不同的生成 ClientID 和 PrivateKeys,但得到了相同的错误。我还阅读了 gitHub 和 developer.apple.com 上的问题,但没有一个答案对我有帮助。任何人的任何帮助将不胜感激。 以下是我正在处理的代码!
const getClientSecret = () => {
const headers = {
alg: 'ES256',kid: KEY_ID
};
const timeNow = Math.floor(Date.Now() / 1000);
const claims = {
iss: TEARM_ID,aud: 'https://appleid.apple.com',sub: CLIENT_ID,iat: timeNow,exp: timeNow + 15777000
};
const token = jwt.sign(claims,PRIVATEKEY,{
algorithm: 'ES256',header: headers
// expiresIn: '24h'
});
return token;
}
const clientSecret = getClientSecret();
const params = {
grant_type: 'authorization_code',// refresh_token authorization_code
code: req.body.code,//apple Login Token
//redirect_uri: [REDIRECT_URI],client_id: CLIENT_ID,client_secret: clientSecret
// refresh_token:body.id_token
};
try {
axios.request({
method: 'POST',url: 'https://appleid.apple.com/auth/token',data: querystring.stringify(params),headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(response => {
console.log('response',response);
}).catch(error => {
console.log('error1',error.response.data);
res.send({
success: false,error: error.response.data
})
})
} catch (error) {
console.log('error',error);
}
statusCode: 400,error: '{"error":"invalid_client"}'
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)