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: How can i get an acces token without a login?

How can i get an acces token without a login?

Alex_Ch
Helpful | Level 5
Go to solution

why am I using Dropbox?

I´m developing a project with react. It's pretty simple, just a form where ussers send a pdf file. The thing I want to do is just that the ussers send their file and its uploaded to my dropbox account in its app folder. 

 

what im having trouble with:

I were testing with the generated token in app console, but i need a way to have an access token. How could i get an access token witout a login?, i just need that the ussers send the files to my app folder in my dropbox

 

I apologize for my poor choice of words, I`m new in this topic

19 Replies 19

Greg-DB
Dropbox Staff
Go to solution

@Alex_Ch It is not possible to "pre-generate" the refresh token. A refresh token can only be retrieved by authorizing the app using the app authorization flow. The refresh token doesn't expire though, so that only needs to be done once per Dropbox account (though the refresh token can be revoked on demand).

Здравко
Legendary | Level 20
Go to solution

@Alex_Ch wrote:

...
Just one more question, how do I pre-generate the refresh token? ...



@Здравко wrote:

... You can take a look here how you can get all needed by hand; ...


... all needed, including refresh token. 😉

Alex_Ch
Helpful | Level 5
Go to solution

In the SDK for javascript that`s the "get access token from code"?, how could I use it to get the refresh token?

Здравко
Legendary | Level 20
Go to solution

@Alex_Ch wrote:

... "get access token from code"?, how could I use it to get the refresh token?


You cannot! Access token is generated from refresh token, not opposite!!! Didn't you read all posted till now? 🤷

Greg-DB
Dropbox Staff
Go to solution

@Alex_Ch When using the OAuth app authorization flow, Dropbox gives an "authorization code" (sometimes also called "access code") that can be exchanged (once) for the access token and optional refresh token. As Здравко said, that resulting refresh token can then be used to retrieve further access tokens as needed. There's an example of that flow in this blog post. That's the same flow implemented by the JavaScript SDK, such as in this example.

Alex_Ch
Helpful | Level 5
Go to solution

Excuse me if I confuse with something, this topic is kinda new to me

I`ve been testing the auth flow, and when I tried to get the authorization code I got a login screen. Is there another way to get the authorization code without that login? The app only needs access to my own account

Здравко
Legendary | Level 20
Go to solution

@Alex_Ch wrote:

... Is there another way to get the authorization code without that login? ...


No, it's not.

 


@Alex_Ch wrote:

... The app only needs access to my own account


Ok, so you need to perform OAuth (including receiving access code) once, as Greg said, and no more. Once you have refresh token you don't need to open any login screen. The refresh token, application key, and (optionally - becomes mandatory for no PKCE) application secret are enough for automatic access token regeneration without any further user interaction (including interaction to you).

Alex_Ch
Helpful | Level 5
Go to solution

Ok, I think I finally got it.

Just one more thing. In the SDK for javascript, I tried to use the command "refreshAccessToken", but it doesn´t read the scopes, I always get the "Scope must be an array of strings" error, even when I define the array in the property.

Where could I find an example of that command? I think I´m using the syntax wrong 

Greg-DB
Dropbox Staff
Go to solution

@Alex_Ch You do not need call refreshAccessToken yourself, unless you need to retrieve a client with a sub-set of the authorized scopes. The SDK will automatically perform the refresh process for you automatically for the currently authorized scopes without you calling refreshAccessToken in your own code.

 

If you do want to call refreshAccessToken explicitly though, you could do so like this:

dbx.auth.refreshAccessToken()
  .then(function() {
    // ...
  })
  .catch(function(error) {
    console.error(error);
  });

 

To call refreshAccessToken with a specific set of scopes, pass in a list like this:

dbx.auth.refreshAccessToken(["account_info.read", "sharing.read"])
  .then(function() {
    // ...
  })
  .catch(function(error) {
    console.error(error);
  });

 

Alex_Ch
Helpful | Level 5
Go to solution

@Greg-DB @Здравко

Thanks, it´s working well. Thanks for the help 

Need more support?