dropbox / dropbox-sdk-rust

Dropbox SDK for Rust
Apache License 2.0
77 stars 18 forks source link

Updating the token via AuthorizationState::Refresh does not update token correctly #85

Closed dennishall3 closed 10 months ago

dennishall3 commented 2 years ago

Hello, and thank you for the great SDK !

Describe the bug When using an UserAuthDefaultClient with an AuthorizationState::Refresh, the obtention of access_token does not work and returns the following error:

BadRequest({"error": "invalid request", "error_description": "No auth function available for given request"}).

To Reproduce Create a client with

UserAuthDefaultClient::new(Authorization::from_refresh_token(client_id, refresh_token))

and try to use it. The obtain_access_token method will fail.

Expected Behavior The access token should be obtained without any problem.

Actual Behavior There was an error.

Versions

Additional context After investigation a bit, here is what I found.

The doc specifies the following request to get an access_token:

curl https://api.dropbox.com/oauth2/token \
    -d grant_type=refresh_token \
    -d refresh_token=<REFRESH_TOKEN> \
    -u <APP_KEY>:<APP_SECRET>

but I feel like the SDK is actually doing:

curl https://api.dropbox.com/oauth2/token \
    -d grant_type=refresh_token \
    -d refresh_token=<REFRESH_TOKEN> \
    -d client_id=<APP_KEY>
```.

Note: after some tests, it seems like:

```bash
curl https://api.dropbox.com/oauth2/token \
    -d grant_type=refresh_token \
    -d refresh_token=<REFRESH_TOKEN> \
    -d client_id=<APP_KEY>
   -d client_secret=<APP SECRET>

also works.

Thank you

wfraser commented 10 months ago

This should be fixed by #143. If you get a chance, please see if it fixes it for you.

My apologies for the lengthy delay. I only just realized why I never repro'd this: my tests and personal use cases relied on old API apps which used long-lived tokens. 🤦