强制新的Dropbox API刷新令牌
我经历了不小心删除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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了为用户获得新的刷新令牌,用户确实需要使用
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).