Login Required 401 using Google ServiceAccountCredential using Google Admin Directory API

前端 未结 2 1345
孤城傲影
孤城傲影 2021-01-23 15:42

I have tried to follow the simple example listed here: https://developers.google.com/admin-sdk/directory/v1/quickstart/dotnet

The difference is I generated a Service Acc

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-23 16:08

    The missing piece of the puzzle is this line:

    ServiceAccountCredential sac = GoogleCredential.FromFile(Secret)
        .CreateScoped(Scopes)
        .UnderlyingCredential as ServiceAccountCredential;
    

    Needs to be modified to this:

    static string userName = "admin@yourdomain.com" // valid user in your org
    
    ServiceAccountCredential sac = GoogleCredential.FromFile(Secret)
        .CreateScoped(Scopes)
        .CreateWithUser(userName)
        .UnderlyingCredential as ServiceAccountCredential;
    

    Java/Python/Go sample of doing similar is here: https://developers.google.com/admin-sdk/directory/v1/guides/delegation#create_the_service_account_and_its_credentials

提交回复
热议问题