cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Great and all as it is to hear how we use Dropbox, we want to know how you use it! Day to day, big projects, sharing files with friends and family - we want to know about it.

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: 

Java SDK - No refresh token?

Java SDK - No refresh token?

OPunktSchmidt
Explorer | Level 3

Hey,

 

i try to get the refresh token with the Java SDK (Android App).

 

I start authentication with this:

 

Auth.startOAuth2Authentication(getContext(), "abc");

And then in onResume:

 

@Override
public void onResume() {
super.onResume();

if (_isCloudAuthFlow) {

_isCloudAuthFlow = false;

String token = Auth.getOAuth2Token();
String refresh = Auth.getDbxCredential().getRefreshToken();
_businessLogic.getSharedPreferences().edit().putString(getString(R.string.all_settings_dropbox_authtoken), token).apply();
}
}

 I get a authToken but the refresh token is always null.

 

Can you help?

1 Accepted Solution

Accepted Solutions

Re: Java SDK - No refresh token?

Greg-DB
Dropboxer

The startOAuth2Authentication method uses the old flow, which currently gives legacy "long-lived access tokens", which don't expire by themselves. Note that starting September 30th, 2021 Dropbox will no longer return new long-lived access tokens, so you should switch to the new flow.

 

The startOAuth2PKCE uses the new flow, which gives "short-lived access tokens", which do expire by themselves, as well as "refresh tokens", which don't expire by themselves.

View solution in original post

6 Replies 6

Re: Java SDK - No refresh token?

Greg-DB
Dropboxer

You should use the startOAuth2PKCE method instead of startOAuth2Authentication now. You can find an example here: 

 

https://github.com/dropbox/dropbox-sdk-java/blob/3162efeccaca247e25553acd21f6ac0bf9018ad6/examples/a...

Re: Java SDK - No refresh token?

OPunktSchmidt
Explorer | Level 3

@Greg-DB wrote:

You should use the startOAuth2PKCE method instead of startOAuth2Authentication now. You can find an example here: 

 

https://github.com/dropbox/dropbox-sdk-java/blob/3162efeccaca247e25553acd21f6ac0bf9018ad6/examples/a...


Yes, with the startOAuth2PKCE - Method i get a refresh token. Does the authToken with startOAuth2Authentication - Method never expire?

Re: Java SDK - No refresh token?

Greg-DB
Dropboxer

The startOAuth2Authentication method uses the old flow, which currently gives legacy "long-lived access tokens", which don't expire by themselves. Note that starting September 30th, 2021 Dropbox will no longer return new long-lived access tokens, so you should switch to the new flow.

 

The startOAuth2PKCE uses the new flow, which gives "short-lived access tokens", which do expire by themselves, as well as "refresh tokens", which don't expire by themselves.

Re: Java SDK - No refresh token?

OPunktSchmidt
Explorer | Level 3

Thanks

Re: Java SDK - No refresh token?

marcoalt
Explorer | Level 4

can you clarify if the only thing I need to do is to set short lived token online in the console, and then use this different authorization method, and the API will take care of it, or if I need to do anything different? I don't understand if I need to store any access token or if I need to make different calls later. Thank  you

 

Normally I check if I have the token, then call:

Auth.startOAuth2Authentication(getActivity(), db_k);

 

While now I call:

Auth.startOAuth2PKCE(context, db_k, DbxRequestConfig.newBuilder("app")
.withHttpRequestor(new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient()))
.build(), Collections.singleton("files.content.write"));

 

Which gives me a token, that then I store, and re-use the following time and also for the actual operation:

DropboxClientFactory.init(accessToken);
PicassoClient.init(context, DropboxClientFactory.getClient());
DbxClientV2 mDbxClient = DropboxClientFactory.getClient();

mDbxClient.files().uploadBuilder("/"+recordingToExport.getName()+"_Features.csv")
.withMode(WriteMode.OVERWRITE)
.uploadAndFinish(inputStream);

How does this code change when using short lived access tokens?

 

Your documentation on github doesn't seem to use any of this. Please help

Re: Java SDK - No refresh token?

Greg-DB
Dropboxer

@marcoalt I see you've also opened a new thread for this, so I'll follow up with you there.

Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    marcoalt Explorer | Level 4
  • User avatar
    OPunktSchmidt Explorer | Level 3
What do Dropbox user levels mean?
Need more support?