-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to short-term / refresh tokens #103
Comments
Thank you for pointing out. I checked this at some point after September 2021; I don't remember exactly when it was, maybe November 2021, but long-lived access tokens were still supported at that time. Though I just checked again, and it looks like Dropbox has finally removed support for long-lived access tokens. I will add support for the new tokens, but this might take me some time to get around to doing. PRs are also welcome. |
I second this. git-remote-dropbox is unusable until this is fixed. Tokens expire after 4h. Idea for a hacky solution in the mean time:
My python is very rusty, but I'll try to copy/paste something together. If somebody with better python skills does this, please post you solution here. |
I think this update shouldn't be that hard to implement. What would be the preferred new workflow though?
Either way, various new request and error handling will need to be added, but it should be pretty straightforward. I may be able to help. |
I'll note that during the bootstrap step to get the refresh key, where it's necessary for the user to click a link like this (from the blog post mentioned above):
The "client id" here is the same as the app key, and the redirect URI property isn't necessary. After clicking through and authorizing, the user gets a short-lived auth code, and this can be used to get the refresh key. So to bootstrap, the app will need to know the app key and app secret, and then have the user retrieve the first short-lived key one time, but after that it can refresh internally. There's no need for anyone to use the "Generate" button on the app console. |
I think we should switch to using PKCE. git-remote-dropbox can store a refresh token in the config file, and whenever it needs to connect to Dropbox, use We can actually simplify the setup process with this. Rather than making every user create a new Dropbox app, we can just create a single production app, hard-code its We can add a This will drop multi-account support (I am not sure how many people were using that). If there's demand, we could add it back. I have started implementing this, but I am not sure how much time I will have to work on it in the next week or so. |
After reviewing the stuff about PKCE, I agree. I wasn't sure about the best practice here but Dropbox recommends doing just as you say. What's the reason for dropping multi-account support? Couldn't the config file just store a separate refresh key for each account? (Edit: I imagine that Alice and Bob shouldn't be storing their keys in the same local user account on a machine, but I can see someone having both personal and work Dropbox accounts.) I can see why the option to use inline tokens might need to be removed though. Does the |
No strong reason for dropping multi-account support besides it slightly complicating the command-line interface (
It gets a fresh token through the refresh token every single time. I think that is the intended use. |
As long as getting a fresh token every time doesn't add unnecessary latency, it seems fine. If people have concurrent uses running, hopefully requesting several keys around the same time won't invalidate the ones that haven't been used yet. My first thought had been to use a lockfile mutex on the config file or something and make sure to refresh the short-lived key if 3 hours have passed, but otherwise to just reuse the short-lived key. If someone is using inline tokens with a legacy permanent token, maybe it's not bad to leave that feature alone, with the understanding that it's no longer useful for new keys. |
It adds some latency (maybe 200-500ms, I didn't measure carefully; I can measure more carefully before merging in this change / add caching if it's problematic). Concurrent requests seem to work out fine. |
If we're overhauling the authentication system, perhaps using a more secure way to save keys could be good. Currently, the API key (which will then become an APP_KEY) is stored in plain text in a json file. If git-remote-dropbox were to query a shell variable, the key could be setup in the following way: The users export DROPBOX_APP_KEY="$(pass Dropbox/AppKey)" And they could use gnu-pass to store his key encrypted by running
|
@ChausseBenjamin Just trying to clarify, but I think the "app key" in this context is just the public unique identifier for the Dropbox app, which will be public information specific to the official |
I've implemented support for PKCE/refresh tokens in #104. I'd really appreciate it if anyone could give feedback on the docs and help test out the code to make sure everything works. |
I just tried it and get a permission error on some files: Traceback (most recent call last): |
Thanks to @mohorko for finding this issue [1]. [1]: #103 (comment)
Thank you! I had not tested on Windows. Fixed in 8c42c86. (And tested on Windows 10 / Python 3.10.1) |
I just tried 3d42d65 and have a new problem with git dropbox login - it only wait a couple of seconds before exiting, which is not enough time to copy the code from dropbox. Sometimes it return a KeyboardInterrupt error, sometime not. $ git dropbox login
EDIT: this problem seems to be specific to MINGW64 terminal that comes installed with git on windows. I tried it with the windows console and it worked flawlessly. |
Thanks for checking that it works with the Windows console. I tested on Windows with Git Bash and it's also working correctly there. We're not doing anything fancy to read this input, just using the Python |
Does |
As part of the migration, perhaps it would be good to put a copy of the long-lived |
Switching to the refresh token doesn't invalidate the long-lived token, so if users are using that on another machine, it will continue to work. |
Well, what I mean is, someone may have multiple Python project envs on the same machine with different versions of git-remote-dropbox installed in them. Maybe there's some reason why they can't (or don't want) to upgrade them all at the same time. The migration changes the old json file in such a way that isn't backwards-compatible (even if it retains the long-lived token), so some of those local installs of the app will fail to read the config after the migration. However, it's backwards compatible if the json is formatted with some redundancy like: {
"version": 2,
"tokens": {
"default": [
"long-lived",
"foobarbaz1234567890"
],
"named": {}
},
"default": "foobarbaz1234567890"
} |
Here's another way it could be formatted that's implicitly backwards-compatible: {
"__version__": 2,
"__refresh-tokens__": {
"default": null,
"named": {
"bob": "laskjdf29734987"
}
},
"default": "foobarbaz1234567890",
"jim": "woeuroie876349835"
} Here the top-level keys without underscores are assumed to be long-lived keys as before, while |
One other alternative: {
"__version__": 2,
"__token-types__": {
"default": "long-lived",
"jim": "long-lived",
"bob": "refresh"
},
"default": "foobarbaz1234567890",
"jim": "woeuroie876349835",
"bob": "laskjdf29734987"
} This is probably worse than the previous alternative because in the long run, people will only have refresh tokens, so the |
I don’t think multiple simultaneous installations of different versions of git-remote-dropbox on the same machine is a case I want to optimize for. Your solution to simultaneously supporting both is neat, but it will add a bit of code complexity and maintenance burden.
I just wish I had added config file version checking starting with v1, so users in such a situation (old version of git-remote-dropbox with new version of config file) would see a good error message.
… On Apr 14, 2022, at 9:22 PM, Eric Huber ***@***.***> wrote:
One other alternative:
{
"__version__": 2,
"__token-types__": {
"default": "long-lived",
"jim": "long-lived",
"bob": "refresh"
},
"default": "foobarbaz1234567890",
"jim": "woeuroie876349835",
"bob": "laskjdf29734987"
}
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.
|
As of September 2021, new apps created for Dropbox do not offer long-term token support. This blog post has more details, but essentially tokens must have an expiration date, and the app Oauth2 settings do not allow you to select "No expiration" anymore.
This results in the access tokens only lasting for a short amount of time (less than a day) before the git-remote-dropbox client throws an error when you try to interact with it:
Unable to refresh access token without refresh token and app key
Thus, anyone who has begun to using this tool after September 2021 must manually log in and retrieve a new generated access token every time their token expires, which is not ideal. It seems like git-remote-dropbox should either migrate to short-lived access tokens or refresh tokens, depending on what it is compatible with.
The text was updated successfully, but these errors were encountered: