1

I'm trying to connect to the Google Directory API (REST Resource: users) via Airflow. I want to get a list of users within the organizational google workspace as well as update some attributes. I want to do this programmatically via the service account that has been setup within the project with appropriate scope: https://www.googleapis.com/auth/admin.directory.user.

The domain-wide delegation has also been enabled as well as the admin sdk api. The service account also has full permissions to the project.

However, when I'm trying to run a basic standalone python script using google api client and google oauth2 to test if the service account is able to access the api and get a single user via their email, it's throwing this error:

Error fetching user: 
<HttpError 403 when requesting https://admin.googleapis.com/admin/directory/v1/users/<username>%40<domain>?alt=json 
returned "Not Authorized to access this resource/api". 
Details: 
  "[
    {
       'message': 'Not Authorized to access this resource/api', 
        'domain': 'global', 'reason': 'forbidden'
    }
   ]
">

However, when i add the email of the super admin as the subject for the impersonation, the service account is able to access the user in the directory API.

credentials = service_account.Credentials.from_service_account_file("/path/to/file.json", 
scopes=SCOPES, 
subject="[email protected]")

Nowhere in the documentation it is mentioned that one needs to add the admin email as well. Am I missing something? If I need to add the admin for the service account to impersonate, then what is the point of having Domain-Wide delegation enabled?

1 Answer 1

0

This seems interesting. A similar kind of work/task which I am focusing right now is, extracting the google groups information from the specific groups instead of extracting the whole organizational groups information using the service account and Google admin SDK API.

Is that possible to extract information from only the specific groups. Since It may cause some problems if I get access for the whole groups.

Is thios possible to extract only specific groups information?

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.