0

I have two google workspace accounts for testing. Account A have a service account and in account B I have added the service account for domain wide delegation with the permissions needed for reading/writing to calendar in account B.

Reading events and calendars works. But when trying to create an event using the service account in the resource calendar in account B I get the following error:

{"error":{"errors":[{"domain":"calendar","reason":"requiredAccessLevel","message":"You need to have writer access to this calendar."}],"code":403,"message":"You need to have writer access to this calendar."}}

Permissions added:

enter image description here

It works if we test within one Google Workspace Account.

This is the code

// clientMail is the service account id
// privateKey is the service account key
// subject is also the service account id
const jwtClient = new google.auth.JWT(
 clientMail,
 undefined,
 privateKey,
 [
 'https://www.googleapis.com/auth/calendar',
 ],
 subject,
 );
 let calendar = google.calendar({
 version: 'v3',
 auth: jwtClient,
 });
...
savedEvent = (await calendar.events.insert({ calendarId, requestBody: event })).data;
...
asked Sep 2, 2021 at 11:36
3
  • Please edit your question and include your code. Remember that you need to delegate to a user on the domain. How this is done depends on the programming language you are using. Commented Sep 2, 2021 at 11:55
  • Thanks for feedback, I have done so now. Commented Sep 2, 2021 at 12:33
  • Does this help? stackoverflow.com/a/61932919/11551468 Commented Sep 2, 2021 at 13:30

1 Answer 1

2

You appear to have forgotten to specify which user you want the service account to delegate to.

from google.oauth2 import service_account
SCOPES = ['https://www.googleapis.com/auth/calendar']
SERVICE_ACCOUNT_FILE = '/path/to/service.json'
credentials = service_account.Credentials.from_service_account_file(
 SERVICE_ACCOUNT_FILE, scopes=SCOPES)
delegated_credentials = credentials.with_subject('[email protected]')
answered Sep 2, 2021 at 14:00
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.