This is likely related to Google Directory API returns 403 for user_list with showDeleted=true but I am unfortunately unable to comment yet, and I don't have an answer to offer.
I received a service account from a school's G Suite with the permission
https://www.googleapis.com/auth/admin.directory.user.readonly
The G Suite admin indicated he has delegated domain-wide authority to the account, and I'm able to create the service account JWT and retrieve the access token to call the APIs using the HTTP/REST flow. However, when I call the user get endpoint to request information about an account -
https://www.googleapis.com/admin/directory/v1/users/redacted%40redacted.com?projection=full
I receive the following:
The remote server returned an error: (403) Forbidden.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Not Authorized to access this resource/api"
}
],
"code": 403,
"message": "Not Authorized to access this resource/api"
}
}
I don't have access to their G Suite admin panel so I'm unable to poke around myself, but the admin has confirmed that our client has access to the admin.directory.user.readonly permission everywhere he can find, and we are in a role that has domain-wide access, as noted above. I'm open to suggestions for places the admin might be missing an assigned permission, or anything I might be missing in my approach (though the JWT build/sign and access token retrieval appear to be working as expected). If there's any other useful information I can provide please let me know and I'll update.
UPDATE: The permissions on the account appear to be correct - I was able to retrieve information from users/get in the API Explorer. However, the API Explorer is using the URL
https://www.googleapis.com/admin/directory/v1/users/redacted%40redacted.com?projection=full&key={YOUR_API_KEY}
and I can't find any documentation on the key parameter, either in the Service Account or users/get documentation. I'm including the access_token as a Bearer token in the authentication header as defined in the specs, and when I tried sending it as the key querystring parameter I still received the same 403 error documented above. There's a similar question on Stack (Google API Client users().get(userKey='[email protected]') returns Not Authorized to access this resource/api) with no answer.