googleapis / google-oauth-java-client

Google OAuth Client Library for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot impersonate service account to create calendar events

masquerade75 opened this issue · comments

Hi. I'm trying to implement user impersonation with a google service account and have been having problems for a while, this is the code I am using in Java:

GoogleCredential credential = GoogleCredential
            .fromStream(TestGoogleCalendarEventCreate.class
                .getResourceAsStream("/ph3-rovigo-313910-6094af96ccfc.json"))
            .createScoped(CalendarScopes.all()).createDelegated("no-reply@dutytree.it");

When I try to read the events from a shared calendar, I receive the following authenication error:

com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized
POST https://oauth2.googleapis.com/token

If I don't use impersonation, I am able to read the events but I can't invite attendees to newly created events.
The service account has domain-wide authority enabled in a G-Suite domain

Thanks a lot.

@TimurSadykov friendly ping

@masquerade75 Hi, sorry for the delay. This does not look like an issue with the library: the response you see could be valid if impersonation is not properly configured. If you still experiencing the issue, please contact Google Workspace support.