cancel
Showing results forĀ 
ShowĀ Ā onlyĀ  | Search instead forĀ 
Did you mean:Ā 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results forĀ 
ShowĀ Ā onlyĀ  | Search instead forĀ 
Did you mean:Ā 

Re: Generate access token without client interaction using Dropbox SDK (C# Api Project)

Generate access token without client interaction using Dropbox SDK (C# Api Project)

manishkanwaria
New member | Level 2
Go to solution

Hi Folks,

 

I have a C# API project which has a service that downloads video assets from different sources, i.e., Azure Blob, AMS, and other client environments.

The new client came in with DropBox as the source for videos, and I am finding difficulty in implementing the OAuth flow. 

 

Please note that there will be no user interaction for authorization, and it will be a completely backend process. I have gone through multiple options, but nothing seems to be working for me.

 

I have been manually generating the access token from the generate access token button under the security tab all this time, but I need to automate this process.

 

Any help is appreciated. Thanks

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

If you need long-term access, you'll need to use the OAuth app authorization flow, but this only needs to be done once per account. It is not possible to fully automate the OAuth process where the user chooses to authorize the app and the app then receives the resulting access token and optional refresh token. This needs to be done manually by the user at least once.
 
If your app needs to maintain long-term access without the user manually re-authorizing it repeatedly, the app should request "offline" access so that it gets a refresh token. The refresh token doesn't expire and can be stored and used repeatedly to get new short-lived access tokens whenever needed, without the user manually reauthorizing the app.
 
You can find more information in the OAuth Guide and authorization documentation. There's a basic outline of processing this flow in this blog post which may serve as a useful example. 

 

When you use the official Dropbox API v2 .NET SDK, you do not need to implement all of the code for the OAuth flow yourself. The SDK will do most of the work for you. You can find examples of using this here. If this is only for your own account, you can also opt to perform the OAuth app authorization flow manually once, e.g., as shown in the post linked in my previous paragraph, and plug that in to the .NET SDK. The SDK will handle the refresh process for you when you supply the necessary credentials: the refresh token, app key, and if not using PKCE, app secret.

View solution in original post

7 Replies 7

Greg-DB
Dropbox Staff
Go to solution

If you need long-term access, you'll need to use the OAuth app authorization flow, but this only needs to be done once per account. It is not possible to fully automate the OAuth process where the user chooses to authorize the app and the app then receives the resulting access token and optional refresh token. This needs to be done manually by the user at least once.
 
If your app needs to maintain long-term access without the user manually re-authorizing it repeatedly, the app should request "offline" access so that it gets a refresh token. The refresh token doesn't expire and can be stored and used repeatedly to get new short-lived access tokens whenever needed, without the user manually reauthorizing the app.
 
You can find more information in the OAuth Guide and authorization documentation. There's a basic outline of processing this flow in this blog post which may serve as a useful example. 

 

When you use the official Dropbox API v2 .NET SDK, you do not need to implement all of the code for the OAuth flow yourself. The SDK will do most of the work for you. You can find examples of using this here. If this is only for your own account, you can also opt to perform the OAuth app authorization flow manually once, e.g., as shown in the post linked in my previous paragraph, and plug that in to the .NET SDK. The SDK will handle the refresh process for you when you supply the necessary credentials: the refresh token, app key, and if not using PKCE, app secret.

manishkanwaria
New member | Level 2
Go to solution

Hi Greg-DB,

Thank you for your valuable feedback. Your suggested way really helped :). I am successfully able to generate an access token from the auth code retrieved from the redirect URL through offline mode. I am also glad to hear that the refresh token doesn't expire and can be used to generate short-lived access tokens.

 

The Dropbox client is also initialised successfully; however, now I am running into access problems to the video asset.

 

I have created an app under the app console with the App Folder option. I could see a folder being created as App/MyFolder. However, when I try to download using the below code, I get an exception stating "path/not_found/"

using (var response = await dbx.Files.DownloadAsync("//Apps//MyFolder//VID20230902073536.mp4"))  

Please correct me if I am doing anything wrong.

 

Thanks.

Š—Š“рŠ°Š²ŠŗŠ¾
Legendary | Level 20
Go to solution

Hi @manishkanwaria,

You may try with:

var response = await dbx.Files.DownloadAsync("/VID20230902073536.mp4")

Does it works? šŸ¤”šŸ˜‰

Hope this helps.

manishkanwaria
New member | Level 2
Go to solution

Hi @Š—Š“рŠ°Š²ŠŗŠ¾,

 

Awesome :). This was the very first option I tried, not sure why It did not work in first place, may be I did something wrong there. Thanks for your help it worked now.

Š—Š“рŠ°Š²ŠŗŠ¾
Legendary | Level 20
Go to solution

Hm.. šŸ¤” Did you set single or double slashes when you tried for very first time and it didn't worked? šŸ§šŸ™‚

Hope this reveals the 'mystery'. šŸ˜‰

manishkanwaria
New member | Level 2
Go to solution

Not sure about it @Š—Š“рŠ°Š²ŠŗŠ¾ but I think I missed the / itself. Thanks for your help.

Š—Š“рŠ°Š²ŠŗŠ¾
Legendary | Level 20
Go to solution

Yes, that too @manishkanwaria - good note. šŸ™‚ Just to avoid further confusions: path separator for all paths is single forward slash and all paths always start with a slash (again single slash). Since your application is 'App folder' type, all paths you're going to pass to any API calls have to be rooted on the applications own folder (i.e. leading parts like '/Apps/MyFolder' have to be cut). Violating some of previous rules will lead to error, most often "path/not_found/" (it's clear, I think, why) if some syntactic rule is not violated at the same time that can lead to corresponding other error.

Good luck.

Need more support?