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

TC888's avatar
TC888
Explorer | Level 3
3 years ago

Java SDK: authorizing with a refresh token, getting "no auth function available for given request"

I'm trying to get authorization using refresh token to work in my project, but I'm having some trouble. This is a command line tool that will run as a cron job, so there shouldn't be any user interaction except once when setting up the configuration.

 

I start by maunally going to an authorization URL in a browser:
https://www.dropbox.com/oauth2/authorize?client_id=<removed for security>&response_type=code&token_access_type=offline

 

There, I authorize the app and get a code. Then I run the following Groovy script:

 

String appKey = '<removed for security>'
String appSecret = '<removed for security>'

DbxAppInfo appInfo = new DbxAppInfo(appKey, appSecret)

String accessCode = '<the code I got from the website>' 

DbxRequestConfig config = DbxRequestConfig.newBuilder(appKey).build();
DbxWebAuth webAuth = new DbxWebAuth(config, appInfo)
DbxAuthFinish authFinish = webAuth.finishFromCode(accessCode)
println authFinish.getAccessToken()
println authFinish.getRefreshToken()
println authFinish.getScope() // Returns account_info.read files.content.read files.metadata.read sharing.read sharing.write

 

That works fine, and I get an access token (which I don't think I should need since I'll be using the refresh token) and a refresh token.

I use those in this script, which is testing some of what the final product will need to do:

 

String folderUrl = '<the URL of a shared folder>'

String appKey = '<our app key>'
String accessToken = '<the access token retrieved in the previous script>'
String refreshToken = '<the refresh token retrieved in the previous script>'

DbxRequestConfig config = DbxRequestConfig.newBuilder(appKey).build();
DbxCredential credential = new DbxCredential(accessToken, 1, refreshToken, appKey)
DbxClientV2 client = new DbxClientV2(config, credential);

FolderLinkMetadata metadata = client.sharing().getSharedLinkMetadata(folderUrl)
println metadata

 

(There's actually more of that script, but for the sake of simplicity I truncated it where the error happens.)

 

On the getSharedLinkMetadata call, I get com.dropbox.core.oauth.DbxOAuthException: No auth function available for given request. Searching for that exception on Google, it seems to be pretty generic, so I'm not sure what the specific problem is.
Note that this works if, instead of a refresh token, I use an access token that I generate on the app console web page.
Are there any problems with how I'm doing this? If not, how should I begin troubleshooting?

 

Thanks in advance for the help.

 

  • Since you're not using PKCE, the app secret is required for the refresh process, so you'll need to set appSecret when making your DbxCredential​.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Since you're not using PKCE, the app secret is required for the refresh process, so you'll need to set appSecret when making your DbxCredential​.

    • TC888's avatar
      TC888
      Explorer | Level 3

      That did the trick.  Thanks.