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

Carol

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 Delegating domain-wide authority to the service account https://developers.google.com/accounts/docs/OAuth2ServiceAccount

It does not have code sample for .net. And it seems I only get ServiceAccountCredential in the google .net client library. Here is my code

    static void Main(string[] args)
    {
        string serviceAccountEmail = "[email protected]";
        var certificate = new X509Certificate2(@"clientPrivateKey.p12", "notasecret",  X509KeyStorageFlags.Exportable);

        Console.WriteLine("service account: {0}", serviceAccountEmail);

        ServiceAccountCredential credential = new ServiceAccountCredential(new
        ServiceAccountCredential.Initializer(serviceAccountEmail)
        {
            Scopes = new[] { CalendarService.Scope.Calendar }
        }.FromCertificate(certificate));

        BaseClientService.Initializer initializer = new  BaseClientService.Initializer();            

        initializer.HttpClientInitializer = credential;           
        initializer.ApplicationName = "Google Calendar Sample";
        CalendarService calservice = new CalendarService(initializer);

        // list all the calendars it can see
        try
        {
            var list = calservice.CalendarList.List().Execute();

            if (list.Items.Count > 0)
            {
                foreach(var item in list.Items)
                {
                    Console.WriteLine("Found calendar for account {0}", item.Id);
                }
            }
            else
            {
                Console.WriteLine("Calendar list for this service account is empty");
            }
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

The calendar list is always empty. If I manually share my domain account calendar with this service account in the calendar setting, then this code returns my domain account calendar successfully.

Is there a way to make this service account access all the user's calendar in the domain?

Carol

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 = "[email protected]" // 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 )

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

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

분류에서Dev

Using a naked-domain-redirect service breaks email on my domain

분류에서Dev

Add Event in Calendar Using ASP.NET

분류에서Dev

Google Analytics - Access custom segments through Service Account

분류에서Dev

How to parse this 3rd party JSON service using .NET?

분류에서Dev

How to give crontab access to domain user?

분류에서Dev

How to access multiselect dropdownlist using asp.net c#

분류에서Dev

How get access token from other users

분류에서Dev

Grant access to AWS S3 bucket/folder to users without AWS account

분류에서Dev

Create an installer for domain users

분류에서Dev

Is it wrong to use the domain account in IIS?

분류에서Dev

multiple users remote access using ssh key based authentication

분류에서Dev

Can server-side access to Google Cloud Firestore be restricted for a service account to specific collections?

분류에서Dev

How to let users view a public folder's calendar content without letting them see details within appointments?

분류에서Dev

How to convert datatable to json string output using json.net WCF Rest Service

분류에서Dev

How to grant sudo access to users abc,def,ghi on user jkl

분류에서Dev

How can I audit users and access attempts to SSH on my server?

분류에서Dev

How to access "Allow users to edit ranges" option in Excel VBA

분류에서Dev

.net - Access Linux directory with C# Windows Service

분류에서Dev

How to set account and password in Linux for using a network printer

분류에서Dev

Permissions assigned to Domain Users do not propagate

분류에서Dev

How to make cross-domain ajax Post request using jquery?

분류에서Dev

Weekly calendar in VB.NET

분류에서Dev

Select users associated to Approved list/table using Ms Access 2003/2013 or Sql query

분류에서Dev

Allow users in a local network to access the Internet via pfSense without using a proxy server

분류에서Dev

How to load other users Twitter wall using Hybridauth

분류에서Dev

How to redirect users with unverified emails using Angular UI-Router?

분류에서Dev

How to check if a service is running using WMI in Python?

분류에서Dev

Google APPs managed "unlimited" account storage quota for service account

Related 관련 기사

  1. 1

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

  2. 2

    Using a naked-domain-redirect service breaks email on my domain

  3. 3

    Add Event in Calendar Using ASP.NET

  4. 4

    Google Analytics - Access custom segments through Service Account

  5. 5

    How to parse this 3rd party JSON service using .NET?

  6. 6

    How to give crontab access to domain user?

  7. 7

    How to access multiselect dropdownlist using asp.net c#

  8. 8

    How get access token from other users

  9. 9

    Grant access to AWS S3 bucket/folder to users without AWS account

  10. 10

    Create an installer for domain users

  11. 11

    Is it wrong to use the domain account in IIS?

  12. 12

    multiple users remote access using ssh key based authentication

  13. 13

    Can server-side access to Google Cloud Firestore be restricted for a service account to specific collections?

  14. 14

    How to let users view a public folder's calendar content without letting them see details within appointments?

  15. 15

    How to convert datatable to json string output using json.net WCF Rest Service

  16. 16

    How to grant sudo access to users abc,def,ghi on user jkl

  17. 17

    How can I audit users and access attempts to SSH on my server?

  18. 18

    How to access "Allow users to edit ranges" option in Excel VBA

  19. 19

    .net - Access Linux directory with C# Windows Service

  20. 20

    How to set account and password in Linux for using a network printer

  21. 21

    Permissions assigned to Domain Users do not propagate

  22. 22

    How to make cross-domain ajax Post request using jquery?

  23. 23

    Weekly calendar in VB.NET

  24. 24

    Select users associated to Approved list/table using Ms Access 2003/2013 or Sql query

  25. 25

    Allow users in a local network to access the Internet via pfSense without using a proxy server

  26. 26

    How to load other users Twitter wall using Hybridauth

  27. 27

    How to redirect users with unverified emails using Angular UI-Router?

  28. 28

    How to check if a service is running using WMI in Python?

  29. 29

    Google APPs managed "unlimited" account storage quota for service account

뜨겁다태그

보관