google-auth-library-java icon indicating copy to clipboard operation
google-auth-library-java copied to clipboard

Error getting access token for service account: 401 Unauthorized while calling refresh on Google Credentials

Open nusbahcodes opened this issue 1 year ago • 6 comments

I am using a service account to access the google cloud features like Drive and Contact to save data through my app. I have suddenly started getting this for all users of some clients. Rest of them seem to be working fine.

"exception_class": "com.google.auth.oauth2.GoogleAuthException",
"exception_message": "Error getting access token for service account: 401 Unauthorized
POST https://accounts.google.com/o/oauth2/token, iss: XXXX.iam.gserviceaccount.com
...
Caused by: com.google.api.client.http.HttpResponseException: 401 Unauthorized
POST https://accounts.google.com/o/oauth2/token
    ... suppressed 3 lines
    ... 61 more

Was and still working fine for certain clients, failing for all users of the other client. What setting should I verify? Domain wide delegation is correct. Clients say they haven't changed any setting on their end.

nusbahcodes avatar Oct 30 '24 07:10 nusbahcodes

Hi @nusbahcodes, thanks for reporting this issue. Could we get some code snippets and dependency versions to help us debug this issue? Specifically the versions of the auth library and client libraries (drive + contact).

At first glance, the token endpoint seems odd. I was expecting https://oauth2.googleapis.com/token, but it may by due to an older version of the auth library.

lqiu96 avatar Nov 04 '24 18:11 lqiu96

Lib versions: google-auth-library-oauth2-http-1.23.0.jar google-api-services-drive-v3-rev20221023-2.0.0.jar

nusbahcodes avatar Nov 06 '24 09:11 nusbahcodes

Thanks, but I would need some code snippets to figure out how you're using the library. Would you be able to share that to help with debugging?

lqiu96 avatar Nov 06 '24 14:11 lqiu96

We have raised a support case for the same.

nusbahcodes avatar Nov 06 '24 18:11 nusbahcodes

I am also receiving this error. Is there any known or temporary fix for this?

HasithaM avatar Nov 30 '24 14:11 HasithaM

I am also receiving this error. Is there any known or temporary fix for this?

Apologies, I missed this message. If this is still an issue, can you provide a repro or code samples to help with investigating this?

lqiu96 avatar Jan 27 '25 22:01 lqiu96

Closing this issue due to inactivity. Feel free to re-open if there are any updates or more information

lqiu96 avatar Apr 02 '25 20:04 lqiu96