I am using Google Directory API .NET Client to fetch a list of roles in a domain (https://developers.google.com/admin-sdk/directory/reference/rest/v1/roles/list).
I use a service account to authenticate on behalf of a user to create the Directory Service. Here is my code:
var initializer = new BaseClientService.Initializer
{
ApplicationName = "GoogleConnector",
HttpClientInitializer = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(connectionDetails.ClientEmail) { User = connectionDetails.UserId, Scopes = scopes }.FromPrivateKey(connectionDetails.PrivateKey)
)
};
var service = new DirectoryService(initializer);
var roles = await service.Roles.List("my_customer").ExecuteAsync();
Now, it works fine without any issues when the user being used for impersonation has a Super Admin role assigned to it. However, providing a Super Admin role to this user is not feasible. When I remove the Super Admin role, assign the following roles:
- User Management
- Groups Reader
- Service Admin
Also, the next request scopes have been added:
- https://www.googleapis.com/auth/admin.directory.rolemanagement
- https://www.googleapis.com/auth/admin.directory.rolemanagement.readonly
The api starts failing with the below error:
Not Authorized to access this resource/
api [403] Errors [ Message[Not Authorized to access this resource/api] Location[ - ] Reason[forbidden] Domain[global] ]
EDIT (after the comment about missing delegation to a domain user)
I have provided domain-wide delegation to the client application (since I am using a service account, following the guide) with all the required scopes:

Also, all other API works fine. I am using groups.list and users.list methods without any issues. Those return the results as usual.
The issue only is with the roles.list method.
Any help is appreciated.

https://www.googleapis.com/auth/admin.directory.rolemanagementandhttps://www.googleapis.com/auth/admin.directory.rolemanagement.readonly(Based from the article)?