强制新的Dropbox API刷新令牌

发布于 2025-01-29 19:11:56 字数 3065 浏览 3 评论 0原文

我经历了不小心删除Dropbox API的刷新令牌,当我尝试获取新的时,只会返回访问令牌。

def generate_refresh_token():
    env = os.environ

    auth_flow = DropboxOAuth2FlowNoRedirect(
        env["DROPBOX_APP_KEY"],
        env["DROPBOX_APP_SECRET"],
        token_access_type="offline",
    )

    authorize_url = auth_flow.start()
    print(f"1. Go to: {authorize_url}")
    print('2. Login with the dropbox service account!\nClick "Allow" (you might have to log in first).')
    print("3. Copy the authorization code.")
    auth_code = input("Enter the authorization code here: ").strip()

    oauth_result = auth_flow.finish(auth_code)
    print("[green]Successfully connected to Dropbox[/green]")
    if oauth_result.refresh_token:
            print(f"[green]Refresh token: <{oauth_result.refresh_token}>[/green]")
    else:
            print(f"[red] No refresh token recieved! [/ref]")

if __name__ == '__main__':
  generate_refresh_token()

返回的oauth_result没有刷新令牌的地方,

──────────────────────── <class 'dropbox.oauth.OAuth2FlowNoRedirectResult'> ────────────────────────╮
│ Authorization information for an OAuth2Flow performed with no redirect.                            │
│                                                                                                    │
│ ╭────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ OAuth2FlowNoRedirectResult(sl.BH3bS7tvBehDQLnMJ0mYYzTAMC3jqhogm8_OK0Hmg5E7-ShZYzMCxaZ4sTNUWM44 │ │
│ │ gyIk06YnQl4uncEor0TAvJyDVb0EQyGZO8mm-UY93l4FL8GT-TRssd43Pb3z768-VC55m4JI,                      │ │
│ │ dbid:AACM6APiewEZWXE0BUtmiqKBaWFwUd3n9ks, 1243637441, , 2022-05-18 17:00:16.906272,            │ │
│ │ account_info.read files.content.read files.content.write files.metadata.read sharing.read      │ │
│ │ sharing.write)                                                                                 │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                    │
│  access_token = 'sl.BH3bS7tvBehDQLnMJ0mYYzTAMC3jqhogm8_OK0Hmg5E7-ShZYzMCxaZ4sTNUWM44gyIk06YnQl4un… │
│    account_id = 'dbid:AACM6APiewEZWXE0BUtmiqKBaWFwUd3n9ks'                                         │
│    expires_at = datetime.datetime(2022, 5, 18, 17, 0, 16, 906272)                                  │
│ refresh_token = ''                                                                                 │
│         scope = 'account_info.read files.content.read files.content.write files.metadata.read      │
│                 sharing.read sharing.write'                                                        │
│       user_id = '1243637441'                                                                       │
╰────────────────────────────────────────────────────────────────────────────────────────────────────╯

是否有一种方法可以强制dropbox返回同一用户的新刷新令牌而无需创建新应用程序?

I have experienced accidentally deleting the refresh token to the Dropbox API and when I try to get a new, only an access token is returned.

def generate_refresh_token():
    env = os.environ

    auth_flow = DropboxOAuth2FlowNoRedirect(
        env["DROPBOX_APP_KEY"],
        env["DROPBOX_APP_SECRET"],
        token_access_type="offline",
    )

    authorize_url = auth_flow.start()
    print(f"1. Go to: {authorize_url}")
    print('2. Login with the dropbox service account!\nClick "Allow" (you might have to log in first).')
    print("3. Copy the authorization code.")
    auth_code = input("Enter the authorization code here: ").strip()

    oauth_result = auth_flow.finish(auth_code)
    print("[green]Successfully connected to Dropbox[/green]")
    if oauth_result.refresh_token:
            print(f"[green]Refresh token: <{oauth_result.refresh_token}>[/green]")
    else:
            print(f"[red] No refresh token recieved! [/ref]")

if __name__ == '__main__':
  generate_refresh_token()

where the returned oauth_result has no refresh token

──────────────────────── <class 'dropbox.oauth.OAuth2FlowNoRedirectResult'> ────────────────────────╮
│ Authorization information for an OAuth2Flow performed with no redirect.                            │
│                                                                                                    │
│ ╭────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ OAuth2FlowNoRedirectResult(sl.BH3bS7tvBehDQLnMJ0mYYzTAMC3jqhogm8_OK0Hmg5E7-ShZYzMCxaZ4sTNUWM44 │ │
│ │ gyIk06YnQl4uncEor0TAvJyDVb0EQyGZO8mm-UY93l4FL8GT-TRssd43Pb3z768-VC55m4JI,                      │ │
│ │ dbid:AACM6APiewEZWXE0BUtmiqKBaWFwUd3n9ks, 1243637441, , 2022-05-18 17:00:16.906272,            │ │
│ │ account_info.read files.content.read files.content.write files.metadata.read sharing.read      │ │
│ │ sharing.write)                                                                                 │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                    │
│  access_token = 'sl.BH3bS7tvBehDQLnMJ0mYYzTAMC3jqhogm8_OK0Hmg5E7-ShZYzMCxaZ4sTNUWM44gyIk06YnQl4un… │
│    account_id = 'dbid:AACM6APiewEZWXE0BUtmiqKBaWFwUd3n9ks'                                         │
│    expires_at = datetime.datetime(2022, 5, 18, 17, 0, 16, 906272)                                  │
│ refresh_token = ''                                                                                 │
│         scope = 'account_info.read files.content.read files.content.write files.metadata.read      │
│                 sharing.read sharing.write'                                                        │
│       user_id = '1243637441'                                                                       │
╰────────────────────────────────────────────────────────────────────────────────────────────────────╯

Is there a way to force Dropbox to return a new refresh token for the same user without having to create a new application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南街女流氓 2025-02-05 19:11:56

为了为用户获得新的刷新令牌,用户确实需要使用token_access_type =“ offline”来处理OAuth应用授权,如下所示。不必完全创建一个新应用程序。

这是您正在运行的确切代码吗?您在这里共享的代码看起来正确,并且在我运行时确实为我打印了刷新令牌(插入应用程序/秘密)。

In order to get a new refresh token for a user, the user does need to process the OAuth app authorization, with token_access_type="offline", as shown here. It is not necessary to create a new application entirely.

Is this the exact code you're running? The code you shared here appears correct, and does work and print out a refresh token for me when I run it (plugging in an app key/secret).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文