403 error Not Authorized to access this resource/api Google Admin SDK in web app even being admin

2024/10/13 20:20:29

I'm struggling to find the problem since two days without any idea why I get this error now even though the app was fully functional one month before.

Among the tasks done by the web app, it makes an Admin SDK API call to get the list of members of a group. The app has the scope https://www.googleapis.com/auth/admin.directory.group.readonly, but I get the 403 error "Not Authorized to access this resource/api" (I verified that the Admin SDK API was enabled in Google's Console). By the way, the app had no problem to make a request to Google Classroom API before.

The most incredible thing here is that the app secrets have been generated by an admin account. And that I get this error when I log into the app with this same admin account. However, when I do tests with the documentation's (https://developers.google.com/admin-sdk/directory/v1/reference/members/list#response) I get a 200 response without a problem with exactly the same authorized scope.

Getting the list of members worked without a problem before with this admin account. Since then, nothing has changed in source code or in configuration so far as I know. So I think the problem may be related to the client secrets in some way, but I have no idea how.

This web app will only be used by this admin account

In my research on StackOverflow, I found most things talking about "Google Apps Domain-Wide Delegation of Authority" (https://developers.google.com/admin-sdk/directory/v1/guides/delegation), but I never used this when it worked before. And I would like to avoid this.

Do you have an idea why I get this 403 error with the web app even though it works when just testing the request in the documentation and I'm using a Super-Admin account ?

Edit: I've now tested a simple snippet with "Google Apps Domain-Wide Delegation of Authority" based on this gist https://gist.github.com/MeLight/1f4517560a9761317d13ebb2cdc670d3 and the snippet alone works. However, when using it inside my app, I still get the 403 error. I'm getting insane, what could be the permission issue?

Answer

Finally, after knocking my head against the wall, I found what was the problem: the groupKey used to get the members of a group https://www.googleapis.com/admin/directory/v1/groups/groupKey/members had a trailing whitespace.

Yes, that's all. I just had to strip the string in the code (one line in Python) and it all went well.

All I did, searching for permissions / client ID / Delegation of Authority was for nuts it seems.

Seriously, the 403 error “Not Authorized to access this resource/api” of Google's API could have been more explicit.

https://en.xdnf.cn/q/118041.html

Related Q&A

Kivy - My ScrollView doesnt scroll

Im having problems in my Python application with Kivy library. In particular Im trying to create a scrollable list of elements in a TabbedPanelItem, but I dont know why my list doesnt scroll.Here is my…

How to get an associated model via a custom admin action in Django?

Part 2 of this question asked and answered separately.I have a Report and a ReportTemplate. +----+----------+---------------+-------------+ | id | title | data | template_id | +----+-------…

How can I use descriptors for non-static methods?

I am aware that I can use descriptors to change static property as if it were a normal property. However, when I try using descriptors for a normal class property, I end up changing the object it refer…

psycopg2 not all arguments converted during string formatting

I am trying to use psycopg2 to insert a row into a table from a python list, but having trouble with the string formatting.The table has 4 columns of types (1043-varchar, 1114-timestamp, 1043-varchar, …

inherited function odoo python

i want to inherit function in module hr_holidays that calculate remaining leaves the function is :hr_holiday.py:def _get_remaining_days(self, cr, uid, ids, name, args, context=None):cr.execute("&…

ValueError in pipeline - featureHasher not working?

I think Im having issues getting my vectorizer working within a gridsearch pipeline:data as panda df x_train:bathrooms bedrooms price building_id manager_id 10 1.5 3 3000 53a5b119b…

pandas dataframe: meaning of .index

I am trying to understand the meaning of the output of the following code:import pandas as pdindex = [index1,index2,index3] columns = [col1,col2,col3] df = pd.DataFrame([[1,2,3],[1,2,3],[1,2,3]], index…

Extract text inside XML tags with in Python (while avoiding p tags)

Im working with the NYT corpus in Python and attempting to extract only whats located inside "full_text" class of every .xml article file. For example: <body.content><block class=&qu…

Python (Flask) and MQTT listening

Im currently trying to get my Python (Flask) webserver to display what my MQTT script is doing. The MQTT script, In essence, its subscribed to a topic and I would really like to categorize the info it …

I dont show the image in Tkinter

The image doesnt show in Tkinter. The same code work in a new window, but in my class it does not. What could be the problem ?import Tkinterroot = Tkinter.Tkclass InterfaceApp(root):def __init__(self,…