IllegalArgumentException from OAuthApp when passing in tokens
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.
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.
¿Theres an alternative to solve this bug?
Anything? I just came across this issue and I have no way to use my refreshToken without a valid way to construct a credential?
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.