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
donaldp
3 years agoCollaborator | Level 9
Getting invalid request for PKCEOAuthFlow.ProcessCodeFlowAsync
Hi, I'm implementing PKCE now, but getting an invalid request exception. I can't see anything that I'm doing wrong from the doco (it says everything is optional except code and appkey). This i...
Greg-DB
Dropbox Staff
The PKCE flow is the right choice for a client-side app, such as a desktop app. The PKCE flow can be used with or without a redirect URI.
The PKCE flow eliminates the need for the app secret by instead using a code challenge/verifier. That's essentially a temporary secret generated by the app. A redirect URI can be used to return the authorization code to the app, but that's unrelated to the use of a code challenge/verifier.
In order for the PKCE flow to be successful, the code challenge/verifier needs to be validated by the Dropbox server. If it's invalid, the process will fail. Specifically, the code_challenge set on the /oauth2/authorize URL used when retrieving the authorization code needs to correspond to the code_verifier sent to /oauth2/token when attempting to exchange that particular authorization code. You can use the PKCEOAuthFlow in the official Dropbox .NET SDK, which will do most of the work for you.
When using PKCEOAuthFlow in the Dropbox .NET SDK, you need to make sure you use the same instance for both the GetAuthorizeUri step as well as the ProcessCodeFlowAsync step, as shown in that example. That's because the PKCEOAuthFlow class generates the code challenge/verifier when the instance is created.
donaldp
3 years agoCollaborator | Level 9
Hi Greg-DB ,
Thanks for your polite-as-always explanation. 🙂 That wasn't clear to me from the doco that the authorisation URL is different every time (since it's always been the same with non-PKCE), so might be worth highlighting that in the doco for others like me who are converting.
I got it working now with an access token (wanted to try that first so that I can test my code handles it properly when it expires), but I did try to save a refresh token at the same time, as that's what I'll use later, and various info was telling me I would get one with a code authorisation flow, but I didn't get a refresh token, only the access token. Is there another parameter or something I need to specify, because I thought I'd done everything I needed to get the refresh token too (for offline processing).
This is what I have so far...
```
PKCEOAuthFlow=new PKCEOAuthFlow();
AuthorisationURLText=PKCEOAuthFlow.GetAuthorizeUri(OAuthResponseType.Code,APIKEY).ToString(); (plus an option to copy this to the clipboard)
OAuth2Response dxResponse=await PKCEOAuthFlow.ProcessCodeFlowAsync(code,APIKEY);
DxAccessToken=dxResponse.AccessToken;
Trace.Write($"********************************** DxAccessToken is {DxAccessToken}\r\n");
if (dxResponse.ExpiresAt is DateTime) {
DxAccessTokenExpiry=(DateTime)dxResponse.ExpiresAt;
} else {
DxAccessTokenExpiry=DateTime.Now;
}
Trace.Write($"********************************** DxAccessTokenExpiry is {DxAccessTokenExpiry}\r\n");
DxRefreshToken=dxResponse.RefreshToken;
Trace.Write($"********************************** DxRefreshToken is {DxRefreshToken}\r\n");
Authorised=true;
```
But as I said, the refresh token came up blank.
thanks,
Donald.
- Здравко3 years agoLegendary | Level 20
donaldp wrote:..., but I didn't get a refresh token, only the access token. Is there another parameter or something I need to specify, because I thought I'd done everything I needed to get the refresh token too (for offline processing).
...
AuthorisationURLText=PKCEOAuthFlow.GetAuthorizeUri(OAuthResponseType.Code,APIKEY).ToString();...
Hi donaldp,
Yes there is such parameter that you skipped. Refresh token is "in pair" with offline processing, but where you are specifying that? There is such a parameter 'tokenAccessType' (set to Legacy by default). Whenever some example uses refresh token the parameter is set to Offline. 😉 Just do the same.
There is a mistake in code comment and documentation that Legacy means long lived token. Sometime ago - Yes, but now it's obsolete.
- Greg-DB3 years agoDropbox Staff
donaldp Здравко is correct, in order to receive a refresh token, you need to specify "offline" access. With the .NET SDK, you would do so in your GetAuthorizeUri call, by setting tokenAccessType: TokenAccessType.Offline, like in the example here. It looks like that's missing in the GetAuthorizeUri call in the latest code you shared.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,915 PostsLatest Activity: 2 days agoIf 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!