java-asana icon indicating copy to clipboard operation
java-asana copied to clipboard

IllegalArgumentException from OAuthApp when passing in tokens

Open eschultink opened this issue 9 years ago • 4 comments

Trying to migrate to v0.5, we're using the new OAuthApp constructor that accepts a refresh token, as follows:

 OAuthApp oauthApp = new OAuthApp(
 clientId,
 clientSecret,
 redirectUri,
 accessToken,
 refreshToken,
 httpTransport,
 jsonFactory
 );

But we get an exception like the following:

java.lang.IllegalArgumentException: Please use the Builder and call setJsonFactory, setTransport, setClientAuthentication and setTokenServerUrl/setTokenServerEncodedUrl
at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkArgument (Preconditions.java:125)
at com.google.api.client.util.Preconditions.checkArgument (Preconditions.java:49)
at com.google.api.client.auth.oauth2.Credential.setRefreshToken (Credential.java:380)
at com.asana.OAuthApp.<init> (OAuthApp.java:60)

And related, as it's not using Credential.Builder, it doesn't respect use of the JsonFactory/HttpTransport dependencies that are passed into the constructor.

This is actually one-and-the-same bug; If you look at the check failing in Credential, it's that you must first have specified transport/jsonfactory/etc so that it knows how to use the refresh token.

eschultink avatar Nov 10 '16 20:11 eschultink

Hey, @eschultink, thanks for letting us know! It does look like constructing the app with a refresh token passed in isn't doing the right thing - that is, in Google's examples, the code path for not having a refresh token is clearly different from when you do specify a token, so we should be following that lead.

praecipula avatar Nov 15 '16 00:11 praecipula

¿Theres an alternative to solve this bug?

andorep avatar Mar 22 '18 02:03 andorep

Anything? I just came across this issue and I have no way to use my refreshToken without a valid way to construct a credential?

matfury avatar Aug 03 '18 00:08 matfury

Any news on this? As of version 0.8.1 this problem is still not solved. Creating an OAuthApp with a refreshToken is currently not possible.

christophpre avatar Apr 18 '19 11:04 christophpre