You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

jfreer's avatar
jfreer
Explorer | Level 4
3 years ago

400 BadRequest from .Net client when using refresh tokens

We are using the .Net SDK client vs 6.14. We primarily use the Files.GetMetadataSync and Files.SaveUrlAsync api calls. We call the API with a variety of long-lived accessTokens and refreshTokens depending on when our customer initiated their Dropbox connection with us. On a number of recent customers who we setup with refreshTokens, we receive a 400 BadRequest HttpRequestException on every API call we make. We configure the DropboxClient with the refreshToken and our AppKey and AppSecret, leaving the accessToken handling up to the DropboxClient. From the returned stack trace, we see the 400 BadRequest is NOT coming in regards to our API call, but rather from the internal oauth calls the library is making to get an AccessToken.

Can you tell us why we are getting the 400 BadRequest from internal oauth calls and what we can do to rectify it?

Here is the stack trace:

 

at HttpResponseMessage System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at async Task<bool> Dropbox.Api.DropboxRequestHandler.RefreshAccessToken(string[] scopeList)
at async Task<bool> Dropbox.Api.DropboxRequestHandler.CheckAndRefreshAccessToken()
at async Task<Result> Dropbox.Api.DropboxRequestHandler.RequestJsonStringWithRetry(string host, string routeName, string auth, RouteStyle routeStyle, string requestArg, Stream body)
at async Task<TResponse> Dropbox.Api.DropboxRequestHandler.Dropbox.Api.Stone.ITransport.SendRpcRequestAsync<TRequest, TResponse, TError>(TRequest request, string host, string route, string auth, IEncoder<TRequest> requestEncoder, IDecoder<TResponse> responseDecoder, IDecoder<TError> errorDecoder)
at async Task<SaveUrlResponse>

  • There are a number of scenarios that can cause the refresh to fail like this, such as:

    • missing/incorrect/malformed refresh token
    • revoked refresh token (e.g., when the user unlinks the app via https://www.dropbox.com/account/connected_apps , etc.)
    • missing/incorrect/malformed app key
    • incorrect/malformed app secret
    • missing app secret (if the refresh token was retrieved using the non-PKCE flow)

    The response body on that 400 error response would contain a more specific error message, though the .NET SDK unfortunately does not currently expose that. There's an open request to update it to do so.

     

    So, make sure you're supplying the correct values. Since it sounds like this is only happening for a few users though, but for all calls for those users, it may be that the refresh tokens for those users are revoked, in which case you should have the users relink the app to get a new one.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    There are a number of scenarios that can cause the refresh to fail like this, such as:

    • missing/incorrect/malformed refresh token
    • revoked refresh token (e.g., when the user unlinks the app via https://www.dropbox.com/account/connected_apps , etc.)
    • missing/incorrect/malformed app key
    • incorrect/malformed app secret
    • missing app secret (if the refresh token was retrieved using the non-PKCE flow)

    The response body on that 400 error response would contain a more specific error message, though the .NET SDK unfortunately does not currently expose that. There's an open request to update it to do so.

     

    So, make sure you're supplying the correct values. Since it sounds like this is only happening for a few users though, but for all calls for those users, it may be that the refresh tokens for those users are revoked, in which case you should have the users relink the app to get a new one.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,882 PostsLatest Activity: 8 hours ago
325 Following

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 or Facebook.

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!