没有在 YouTube OAuth 中获得刷新令牌
Not getting refresh token in YouTube OAuth
我正在按照 this 指南进行服务器端 OAuth。
我成功完成了 OAuth,但在步骤 交换刷新和访问令牌的授权码:
中没有得到 refresh_token
要求:
POST /o/oauth2/token HTTP/1.1
HOST: accounts.google.com
content-type: application/x-www-form-urlencoded
content-length: 260
code=4/KEOuzih9jwfnHj7Rl1DeqHhcJF0goKPwtwR5IQ09ieg&
client_id=****.apps.googleusercontent.com&
client_secret=****&
redirect_uri=http%3A%2F%2Flocalhost%3A8000%2FsSignIn.html&
grant_type=authorization_code
响应:
{
"access_token" : "****",
"expires_in" : 3580,
"token_type" : "Bearer"
}
我是不是漏掉了什么?
需要完成两件事:
- 要获取刷新令牌,您必须将
access_type=offline
作为查询参数传递给 oauth 启动请求。这将确保您在第一次为帐户执行 oauth 时获得刷新令牌。
- 要在为同一帐户一次又一次地执行 oauth 时获取刷新令牌,您必须将
prompt=consent
作为查询参数传递给 oauth 启动请求。
参考:https://developers.google.com/identity/protocols/OAuth2WebServer#offline
这方面的支持文档非常糟糕且不完整。
这是 php 代码。但是这些设置会产生刷新令牌。
$client->setIncludeGrantedScopes(true);
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
我正在按照 this 指南进行服务器端 OAuth。
我成功完成了 OAuth,但在步骤 交换刷新和访问令牌的授权码:
中没有得到refresh_token
要求:
POST /o/oauth2/token HTTP/1.1
HOST: accounts.google.com
content-type: application/x-www-form-urlencoded
content-length: 260
code=4/KEOuzih9jwfnHj7Rl1DeqHhcJF0goKPwtwR5IQ09ieg&
client_id=****.apps.googleusercontent.com&
client_secret=****&
redirect_uri=http%3A%2F%2Flocalhost%3A8000%2FsSignIn.html&
grant_type=authorization_code
响应:
{
"access_token" : "****",
"expires_in" : 3580,
"token_type" : "Bearer"
}
我是不是漏掉了什么?
需要完成两件事:
- 要获取刷新令牌,您必须将
access_type=offline
作为查询参数传递给 oauth 启动请求。这将确保您在第一次为帐户执行 oauth 时获得刷新令牌。 - 要在为同一帐户一次又一次地执行 oauth 时获取刷新令牌,您必须将
prompt=consent
作为查询参数传递给 oauth 启动请求。
参考:https://developers.google.com/identity/protocols/OAuth2WebServer#offline
这方面的支持文档非常糟糕且不完整。
这是 php 代码。但是这些设置会产生刷新令牌。
$client->setIncludeGrantedScopes(true);
$client->setAccessType('offline');
$client->setApprovalPrompt('force');