Google Oauth 交换代码、刷新令牌和访问令牌
Google Auth Exchange Code , Referesh Token and Access Token
我正在尝试使用 Google 授权交换代码获取 refereh_token, access_token
,浏览了文档但它不起作用,我正在使用 react-google-login对于 Auth 并获得 code
作为响应,我正在传递 code
https://accounts.google.com/o/oauth2/token 但给出错误
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
我试过很多方法
code=4%2FKxoYTS-jeq5-d6Lv7YvSz9ZrK0pJ_5lZsMExzNC1M0o&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&client_id=407408718192.apps.googleusercontent.com&client_secret=************&scope=&grant_type=authorization_code
前端是reactjs,后端是nodejs..
要使用 referesh 令牌获取访问令牌,您必须调用 api,这将为您提供一个新的访问令牌
调用 POST APi https://www.googleapis.com/oauth2/v4/token
将 body 作为 x-www-form-urlencoded 传递,即
Header 作为
Content-Type : application/x-www-form-urlencoded
Body
client_secret : 'xxxxxxxxxxxxdxxxxxSSd'<YourClientSecret>
grant_type : refresh_token'
refresh_token : '1/DDPkddk514451xxxxxxxx' <YourRefreshToken>
client_id : 'xxxxxxxxxxxxxxx' <YourClientID>
如需更多参考,您可以阅读这篇文章https://developers.google.com/identity/protocols/OAuth2WebServer
我正在尝试使用 Google 授权交换代码获取 refereh_token, access_token
,浏览了文档但它不起作用,我正在使用 react-google-login对于 Auth 并获得 code
作为响应,我正在传递 code
https://accounts.google.com/o/oauth2/token 但给出错误
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
我试过很多方法
code=4%2FKxoYTS-jeq5-d6Lv7YvSz9ZrK0pJ_5lZsMExzNC1M0o&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&client_id=407408718192.apps.googleusercontent.com&client_secret=************&scope=&grant_type=authorization_code
前端是reactjs,后端是nodejs..
要使用 referesh 令牌获取访问令牌,您必须调用 api,这将为您提供一个新的访问令牌 调用 POST APi https://www.googleapis.com/oauth2/v4/token
将 body 作为 x-www-form-urlencoded 传递,即
Header 作为 Content-Type : application/x-www-form-urlencoded
Body
client_secret : 'xxxxxxxxxxxxdxxxxxSSd'<YourClientSecret>
grant_type : refresh_token'
refresh_token : '1/DDPkddk514451xxxxxxxx' <YourRefreshToken>
client_id : 'xxxxxxxxxxxxxxx' <YourClientID>
如需更多参考,您可以阅读这篇文章https://developers.google.com/identity/protocols/OAuth2WebServer