在使用刷新令牌获取访问令牌Dropbox v2 API时获取新刷新令牌

人气:439 发布:2022-10-16 标签: dropbox dropbox-api

问题描述

在Refresh token is not returned from Dropbox API when using grant_type=refresh_token

发帖者问他为什么在使用新的Dropbox v2 API时没有获得新的刷新令牌。

答案是不需要它。除非被吊销,否则Dropbox中的刷新令牌不会过期。

现在还是这样吗?我正在阅读https://developers.dropbox.com/oauth-guide

使用刷新令牌时,使用AUTHORIZATION_CODE的GRANT_TYPE调用/OAuth2/Token终结点将返回一个新的短期访问令牌和一个新的刷新令牌,这些令牌应安全存储。&q;

但是当我使用刷新令牌获取访问令牌时,我仍然看不到刷新令牌。

Request:
POST https://api.dropbox.com/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: api.dropbox.com
Content-Length: 363
Expect: 100-continue
Connection: Keep-Alive

refresh_token=<TOKEN>&grant_type=refresh_token&client_id=<ID>&client_secret=<Secret>&scope=account_info.write+account_info.read+files.metadata.write+files.metadata.read+files.content.write+files.content.read+sharing.write+sharing.read+file_requests.write+file_requests.read+contacts.write

Response
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Type: text/javascript
Date: Thu, 29 Apr 2021 13:30:50 GMT
Pragma: no-cache
Server: envoy
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Server-Response-Time: 35
Vary: Accept-Encoding
X-Dropbox-Response-Origin: far_remote
X-Dropbox-Request-Id: 744233e362ac4b20a00e7a862ae90a16
Content-Length: 395

{"token_type": "bearer", "access_token": "token", "expires_in": 14400, "scope": "account_info.read contacts.write file_requests.read file_requests.write files.content.read files.content.write files.metadata.read files.metadata.write sharing.read sharing.write"}

我正在使用.Net API将我的刷新令牌交换为访问令牌。但我不知道如何才能拿回新的刷新令牌,即使它在网上。但事实似乎并非如此。当我使用刷新令牌获取访问令牌时,刷新令牌本身似乎并未过期。这种情况在未来会改变吗?

_DropBoxClient = new DropboxClient(string.Empty, dbap.RefreshToken, sApiKey, sApiSecret, config);
    var newScopes = new string[]
    {
        "account_info.write",
        "account_info.read",
        "files.metadata.write",
        "files.metadata.read",
        "files.content.write",
        "files.content.read",
        "sharing.write",
        "sharing.read",
        "file_requests.write",
        "file_requests.read",
         "contacts.write"
    };
bool success = Task.Run<bool>(async () => await _DropBoxClient.RefreshAccessToken(newScopes)).Result;

推荐答案

Dropbox API/OAuth2/Token终结点在刷新过程中不返回新的刷新令牌,也没有计划让它这样做。官方documentation for the Dropbox /oauth2/token endpoint can be found here。

Dropbox OAuth Guide指的是为grant_type=authorization_code调用/OAuth2/Token时,即首次将授权码交换为短期令牌和(可选)刷新令牌时。(很抱歉,这里的新内容具有误导性。我们会解决的。)

当您调用grant_type=refresh_token的/OAuth2/Token时,即使用刷新令牌获取新的短期访问令牌时,它不会返回另一个刷新令牌。

341