如何从桌面应用程序使用 Dropbox API 进行身份验证?

How to authenticate with Dropbox API from a desktop application?

我正在尝试开发一个 运行 本地用户计算机上的应用程序。我想使用 Dropbox API 来存储和同步一些特定于应用程序的文件。

Dropbox 文档中的所有地方都假定该应用程序是 Web 应用程序。看起来唯一的身份验证选项是通过 OAuth。如果应用程序是 运行 在我自己的服务器上,那么存储应用程序的 secret 代码不是问题(这是 OAuth 所必需的,如 the example ).但就我而言,如果我 运行 一个在用户计算机上实现 OAuth 的 Web 服务器,我将不得不发布 secret.

似乎还有另一种选择 – 运行仅用于身份验证部分的全局服务器,然后重定向回本地主机上的服务器 运行ning。但是我真的不喜欢这个。

那么,我的问题是:
有没有更好的方法从用户的计算机使用 Dropbox API 进行身份验证?
或者可以公开应用程序的 secret?

公开一个人的应用程序秘密当然是不可取的,所以在 OAuth 2 中,包括 Dropbox 的实现,有一种机制可以在 client-side 应用程序中处理 OAuth 流程而不使用应用程序秘密。

具体来说,client-side 应用程序应使用 "token" 流程(与 "code" 流程相对),如记录 here under /oauth2/authorize:

OAuth 2.0 supports two authorization flows:

  • The code flow returns a code via the redirect_uri callback which should then be converted into a bearer token using the /oauth2/token call. This is the recommended flow for apps that are running on a server.

  • The token or implicit grant flow returns the bearer token via the redirect_uri callback, rather than requiring your app to make a second call to a server. This is useful for pure client-side apps, such as mobile apps or JavaScript-based apps.

不幸的是,对于 client-side Python 个应用程序,Dropbox Python SDK 中的 OAuth 流程目前仅针对 server-side 个应用程序构建,因此只实现代码流,不实现令牌流。虽然它是开源的,因此您可以根据需要修改它 if/as,或者单独实现令牌流。

作为更简单的解决方案,您可以发布编码的 secret 并在 server-side 上对其进行解码。

这只是出于安全原因