How to access domain users' calendar using service account in .net?

后端 未结 2 1469
旧时难觅i
旧时难觅i 2021-01-03 14:42

I am using service account with key.p12 cert to access google calendar API. However, it cannot access any user\'s calendar in the domain. I did follow the steps to Delegatin

2条回答
  •  旧时难觅i
    2021-01-03 14:51

    Actually, the code should use service account to "impersonate" the domain users one by one, rather than trying to share calendars with service account.

        ServiceAccountCredential.Initializer(serviceAccountEmail)
        {
            Scopes = new[] { CalendarService.Scope.Calendar },
            User = "myaccount@mydomain.com" // impersonate domain user
        }.FromCertificate(certificate));
    

    Also need follow the steps for Delegating domain-wide authority to the service account in google domain admin console, and add the right scope( for calendar, it is https://www.googleapis.com/auth/calendar )

提交回复
热议问题