0

My nodejs app accesses google calendar api using service account credentials. I'm able create events and also email notifications are being sent to attendees from my personal mail id though I use my domain user id as impersonator. However, if I update events using domain id as impersonator, the emails are sent from domain user mail id which is quite confusing. Is this the expected behaviour? I want all emails to be sent from my personal mail id. Is this possible?

I have done domain wide delegation already using domain user id. For better understanding let me just explain. Now I have three IDs.

  1. My personal Gmail id
  2. Service account id generated using the above personal id.
  3. Domain user id. A separate domain mail id which is provided domain wide delegation of authority for the purpose of inviting guests to events.

Now when I use the domain user id to create events, the mail is sent from my personal email id and not from the domain user id. But on updating events, using the domain user id as impersonator, the mail gets sent from the domain user id and not from my personal id. Which is quite confusing. If I don't give impersonator while updating events, the mail gets sent from service account id. The same is the case for deleting events. Now I want all the email to be sent from personal mail id. And not from service account or the domain id. Please help

Following is the nodejs snippet for impersonation. I have used domain user mail id as impersonator.
this.jwtClient = new JWT(client_email,null, private_key,
                                SCOPES,impersonator);

ziganotschka
  • 25,866
  • 2
  • 16
  • 33

1 Answers1

1

It is hard to understand your issue wihtout seeing your code, but what I can say:

  • If you want the service account to update event on YOUR behalf - then you have to build for this purpose the service account instance impersonating YOU and not any other domain user.

  • Obviously this will only work if you have the permission to update an event - this might not be the case if the event is in a user's private calendar where you are only guest and were not granted the authorization to modify the event.

ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • Hi ziganotschka, Thanks for ur reply. I have updated the post with the code snippet. If I use my personal mail id as impersonator, Im getting unauthorised_Client error. However, it is the same personal mail id I have used to create the service account. – user3008249 Nov 18 '20 at 08:57
  • So is `impersonator` Your emailID? In this case it means that you are not authorized to perform the update you want to. after all, if you created an event in a user's calendar on his behalf - by default you are not allowed to change this event on your own behalf. Unless this calendar is shared with you and you have been granted the permission to make changes. An exeption is if you (`impersonator`) are super admin - see [here](https://support.robinpowered.com/hc/en-us/articles/206441133-Setting-permissions-for-editing-calendar-events). – ziganotschka Nov 18 '20 at 09:21
  • A workaround would be to add yourself during the event creation as an attendee and set the option `guestsCanModify` to `true`. – ziganotschka Nov 18 '20 at 09:28
  • Yes "impersonator" is my personal mail id. However,I'm the calendar owner. Also in the event response received from google api, my personal id is mentioned as event organiser. The domain user id is mentioned as event creator. Does this mean, the event organiser cannot update an event? I have set impersonator as my personal id – user3008249 Nov 18 '20 at 10:13
  • When creating an event in a private calendar - the event creator and organizer will be the same person. If you specify a different organizer in the create request - this specification will be silently dropped. Because organizer is [Read-only, except when importing an event.](https://developers.google.com/calendar/v3/reference/events#resource). – ziganotschka Nov 18 '20 at 11:08
  • I dont quite understand your previous reply. In my case, I have shared my calendar with the service account mail id and the domain user mail id. When I created the event using service account with domain user Id as impersonator, event organiser is set as my personal mail id. and event creator is domain user id. Now when I use my personal mail id to update the event, im getting unauthorised. Im not trying to change the event organiser field at all... Im quite confused now – user3008249 Nov 18 '20 at 11:22
  • To explain in other words: If you created an event on a domain user's behalf - this domain user will be the creator AND organizer oof the event. Setting yourself as an organizer of an event created by someone else is not a valid request and has been ignored by the API. So you are NOT the event organizer, hence you are not authorized to update it. – ziganotschka Nov 18 '20 at 12:16