Hi Guys,
I've been reading a lot of the Dropbox API documents to get OAuth2 authentication working for my offline Windows application using the .NET SDK. The 'OAuth Guide' was a great starting point and very helpful!
I've looked at the code from both these example projects: OAuth Basic and OAuth PKCE
These really helped me to understand it programmatically.
My snippet of code
Uri authorizeUri = DropboxOAuth2Helper.GetAuthorizeUri(OAuthResponseType.Code, ApiKey, redirectUri: (string) null, tokenAccessType: TokenAccessType.Offline);
OAuth2Response tokenResult = await DropboxOAuth2Helper.ProcessCodeFlowAsync(authorizationCode, ApiKey, ApiSecret);
I noticed the returned value (a URI) didn't have an Authorization Code, but a URL (and other related items) to redirect to Dropbox to authenticate manually, i.e. non-offline.
I then tried the non-overloaded method specifically for no-redirect authentication:
DropboxOAuth2Helper.GetAuthorizeUri(ApiKey)
Again it returned a URI containing a URL (and other related items) for redirect (i.e. non-offline) authentication.
Now, I'm thinking this method DropboxOAuth2Helper.GetAuthorizeUri() doesn't handle offline authentication. Or I must be doing something very wrong.
Going back to the documentation, and re-reading the 'OAuth Guide' (https://developers.dropbox.com/oauth-guide), I came across the following paragraph:
Applications that require offline access to the API - meaning using the API when the end user is not actively interacting through your app - will not be able to prompt for re-authorization. These apps may instead use long-lived refresh tokens can be used to obtain new access tokens.
So this document tells me I am able to fetch a long-lived refresh token, then fetch consecutive short-lived (sl-) access tokens as I go.
But I am now unsure how to do this using the .NET SDK? (I'd rather not use HTTP calls and stick to the .NET SDK).
Can someone please provide a snippet of code to show how this can be done, please. Or point me in the right direction. I have spent 3 days on this, which isn't too frustrating as I have learnt a lot about the Dropbox API.
Thanks.