0
我越來越獲取服務器訪問服務器(Google服務帳戶)令牌。 invalid_grant錯誤
{ "error": "invalid_grant", "error_description": "Bad Request" }
當我試圖從谷歌的訪問令牌。我正在關注。我想也許我生成JWT令牌的方式不正確?
var header = { "alg": "RS256", "typ": "JWT" };
var body = {
iss:'[email protected]',
scope: 'https://www.googleapis.com/auth/calendar',
aud: 'https://www.googleapis.com/oauth2/v4/token',
exp: Date.now() + ONE_HOUR,
iat: Date.now(),
};
var token = jsrsasign.jws.JWS.sign('RS256', header, body, googleServicePrivateKey);
return Q.Promise(function(resolve, reject) {
superagent.post('https://www.googleapis.com/oauth2/v4/token')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send({
grant_type: encodeURIComponent('urn:ietf:params:oauth:grant-type:jwt-bearer'),
assertion: token
})
.end(function(err, res) {
if (err) return reject(err);
resolve(res.body);
});
});
我googleServicePrivateKey看起來像
'-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCNPsOIG1HGgMhP\nG...
ISIT好嗎?與那些\n
?