Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException processing GoogleRefreshTokenRequest #932

Closed
artgo opened this issue Mar 10, 2015 · 9 comments
Closed

NullPointerException processing GoogleRefreshTokenRequest #932

artgo opened this issue Mar 10, 2015 · 9 comments
Assignees

Comments

@artgo
Copy link

artgo commented Mar 10, 2015

java.lang.NullPointerException: null
at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull(Preconditions.java:191) ~[google-http-client-1.19.0.jar:1.19.0]
at com.google.api.client.util.Preconditions.checkNotNull(Preconditions.java:127) ~[google-http-client-1.19.0.jar:1.19.0]
at com.google.api.client.json.jackson2.JacksonFactory.createJsonParser(JacksonFactory.java:92) ~[google-http-client-jackson2-1.19.0.jar:1.19.0]
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:85) ~[google-http-client-1.19.0.jar:1.19.0]
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81) ~[google-http-client-1.19.0.jar:1.19.0]
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:88) ~[google-oauth-client-1.19.0.jar:1.19.0]
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287) ~[google-oauth-client-1.19.0.jar:1.19.0]
at com.google.api.client.googleapis.auth.oauth2.GoogleRefreshTokenRequest.execute(GoogleRefreshTokenRequest.java:125) ~[google-api-client-1.19.1.jar:1.19.1]

@artgo
Copy link
Author

artgo commented Mar 12, 2015

I added logging to com.google.api on DEBUG level and see "HTTP/1.1 401 Unauthorized" response with empty body returned.

This definitely needs to be fixed to produce more sensible exception, since NPE usually indicate an issue with the library in this case.

@wonderfly
Copy link
Contributor

This is a duplicated issue and a fix is checked in:
googleapis/google-oauth-java-client@950fd01

The next release, which is under way, will have the fix. For the interim, you could build the libraries from HEAD.

@artgo
Copy link
Author

artgo commented Mar 12, 2015

Thank you, @wonderfly ! Is there any timeline to release the new version?

@wonderfly
Copy link
Contributor

It's scheduled next week.

On Wed, Mar 11, 2015 at 10:08 PM, Artem Golubev notifications@github.com
wrote:

Thank you, @wonderfly https://github.com/wonderfly ! Is there any
timeline to release the new version?


Reply to this email directly or view it on GitHub
#932 (comment)
.

Best,
Daniel

@artgo
Copy link
Author

artgo commented Mar 12, 2015

🎆 👯

@aerodc
Copy link

aerodc commented Mar 23, 2015

Hello, I use version 1.20 now, but always have such erreur when refreshToken :

com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized

@wonderfly
Copy link
Contributor

That could be caused by many things: invalid client ID, client secret or
scopes. But it could also be due to refresh token overuse:

https://developers.google.com/accounts/docs/OAuth2#basicsteps
(Take a look at the special note trailing the 4th bullet)

How often do you send refreshToken requests and how often do you get 401s?

On Mon, Mar 23, 2015 at 9:59 AM, dc notifications@github.com wrote:

Hello, I use version 1.20 now, but always have such erreur when
refreshToken :

com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized


Reply to this email directly or view it on GitHub
#932 (comment)
.

Best,
Daniel

@Zeimyth
Copy link

Zeimyth commented Jul 10, 2015

@wonderfly I am seeing the same error as @aerodc. I am using v2-rev165-1.20.0.

I know for sure that this is not a client ID problem, nor a client secret problem, because I can perfectly reproduce cases where I get the 401 and cases where I don't. Cases where I get the 401 go something like this:

  1. A user who has never used my app with their Google account logs in using Google Single Sign-on. My app requests the email and profile scopes.
  2. This user later decides they want to use my app's Drive integration. They link their account on my app to Google Drive. My app requests the email, profile, drive.file, install, and offline scopes.
  3. Requests to Google Drive using this user's access token work. Refreshing this user's access token works (as verified by waiting a day and repeating the aformentioned request successfully). Requests to Google Drive using my app's service account on this user's behalf always return a 401.

However, if I do things slightly differently, I can avoid the 401 altogether:

  1. A user who has never used my app signs up without using Google SSO.
    • Alternatively, the user from the previous steps unlinks their Drive account with my app and revokes all permissions they had given to my app
  2. The user decides they want to use my app's Drive integration. They link their account, and my app requests the email, profile, drive.file, install, and offline scopes.
  3. Requests to Google Drive using this user's access token work. Requests to Google Drive using my app's service account on this user's behalf also work. No requests return a 401.

I have tracked this behavior down to the same exception that aerodc was seeing:
com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized

I don't know why Google's servers are giving back a 401. I know that my client ID and secret are correct, because I am able to make some calls (as in the second scenario) without getting a 401. I don't think the problem has anything to do with refreshToken requests either; I am not explicitly requesting refresh tokens outside of whatever the Java client does automatically, and my code's behavior between the two scenarios doesn't change. Am I doing something wrong with scopes, then?

I know it's not the Java client's fault, per se - I'm quite happy that the exception is no longer just a NullPointerException. But I wish the Google servers would actually send an explanatory response body to begin with. That would help me understand what I'm doing wrong, as well as solving the NullPointerException problem indirectly. I feel like the fix to the NullPointerException is only half a fix; we simply have exchanged one exception type for another.

@mattwhisenhunt
Copy link
Contributor

This issue may no longer be relevant due to its age. Feel free to re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants