Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
Dearbhla
8 years agoExplorer | Level 3
Migration from v1 to v2 API - automatic token upgrade
Hi I'm wondering about the call to https://api.dropbox.com/1/oauth2/token_from_oauth1 to automatically upgrade a user's token from the v1 to the v2 api. I have this working well in m...
- 8 years ago
You don't need to be already authorized for API v2 to use this endpoint. This endpoint just requires the app key, secret, and OAuth 1 access token (key and secret), not an OAuth 2 access token.
The issue you're running in to is that /2/auth/token/from_oauth1 uses "app authentication" (i.e., you should provide the app key and secret as Basic auth to authorize the HTTP call itself) but you're trying to use "user authentication" (i.e., you're trying to provide a Bearer token to authorize the API call itself). The expected authentication type is a field in the documentation here:
https://www.dropbox.com/developers/documentation/http/documentation#auth-token-from_oauth1
You can find information on the different authentication types, e.g., "app authentication", here:
https://www.dropbox.com/developers/reference/auth-types#app
(This is a bit confusing in this case, since the /2/auth/token/from_oauth1 endpoint expects "app authentication", but also happens to take an access token key/secret as parameters to the API call.)
So, for your HTTP request, you should instead use an Authorization header like this:
Authorization: Basic <base64(APP_KEY:APP_SECRET)>The app authentication documentation elaborates on that example.
We're also working on building this in to SwiftyDropbox itself, but that's not ready quite yet.
Dearbhla
8 years agoExplorer | Level 3
Hi Greg
Thanks for the response. I've been unable to get this to work as it seems to require me to be authorised already for V2. Is this right?
I am trying to use it like this (on the Mac and iOS using the objective-C V1 Core SDK and the SwiftyDropbox V2 SDK in the same app):
1. User is already logged into V1 - has OAUTH1 token and token secret in keychain
2. User not logged in yet to V2 - ie hasn't got OAUTH2 token in keychain
3. The apps uses the V1 API to get a migrated V2 token using the endpoint:
https://api.dropbox.com/1/oauth2/token_from_oauth1
4. From then on the app uses the V2 API and the new token
This is all working great, but since the V1 endpoint is going to disappear at end of June I'd like to start using the V2 endpoint for the migration as you suggested above.
But since the user isn't logged in using V2 yet, I can't seem to get the V2 endpoint to work - possibly something wrong with authorisation.
Here's the request when I use the V2 endpoint:
POST /2/auth/token/from_oauth1 HTTP/1.1
Host: api.dropbox.com
Content-Type: application/json
User-Agent: MYAPP CFNetwork/760.6.3 Darwin/15.6.0 (x86_64)
Connection: keep-alive
Proxy-Connection: keep-alive
Accept: */*
Accept-Language: en-us
Content-Length: 86
Accept-Encoding: gzip, deflate
Authorization: Bearer <TOKEN>
Pragma: no-cache
Cache-Control: no-cache
{
"oauth1_token" : "yyy",
"oauth1_token_secret" : "zzz"
}
And the response:
HTTP/1.1 400 Bad Request Server: nginx Date: Sun, 12 Mar 2017 15:14:19 GMT Content-Type: text/plain; charset=utf-8 Content-Length: 115 Connection: keep-alive X-Dropbox-Request-Id: a4f6b0905dc3cbe249fd52576f0aacc5 Expires: 0 Cache-Control: no-cache Error in call to API function "auth/token/from_oauth1": Invalid HTTP header "Authorization": expecting "Basic" auth
Am I doing something wrong? What do I put for the "Authorization" header - I'm not sure what to add for <TOKEN> since at this point I don't have a V2 token.
Many thanks
Greg-DB
Dropbox Community Moderator
8 years agoYou don't need to be already authorized for API v2 to use this endpoint. This endpoint just requires the app key, secret, and OAuth 1 access token (key and secret), not an OAuth 2 access token.
The issue you're running in to is that /2/auth/token/from_oauth1 uses "app authentication" (i.e., you should provide the app key and secret as Basic auth to authorize the HTTP call itself) but you're trying to use "user authentication" (i.e., you're trying to provide a Bearer token to authorize the API call itself). The expected authentication type is a field in the documentation here:
https://www.dropbox.com/developers/documentation/http/documentation#auth-token-from_oauth1
You can find information on the different authentication types, e.g., "app authentication", here:
https://www.dropbox.com/developers/reference/auth-types#app
(This is a bit confusing in this case, since the /2/auth/token/from_oauth1 endpoint expects "app authentication", but also happens to take an access token key/secret as parameters to the API call.)
So, for your HTTP request, you should instead use an Authorization header like this:
Authorization: Basic <base64(APP_KEY:APP_SECRET)>
The app authentication documentation elaborates on that example.
We're also working on building this in to SwiftyDropbox itself, but that's not ready quite yet.
- Dearbhla8 years agoExplorer | Level 3
Greg
That worked great. I knew I was doing something wrong.
Many thanks!
About Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!