I was testing the use of the API Key functionality for conducting python automation via the arcgis python api and I expected API Key privileges to apply. However, testing indicated API key privileges were following the user role that owns the key, not the privileges set in the key itself. I'm wondering if there is a bug in the Arcgis API or if I am missing something?
Testing steps:
I examined Privileges | Documentation | Esri Developer to learn about the scope. It appears that the AGOL Portal Service privileges have personal scope “that require additional permissions from your account to perform operations.” However, in this case it seems the privileges for the API Key are being overridden by the user role permissions not enabled by them. When using the arcgis python api, it is not adhering to the privileges of the API Key, nor is it adhering to the privileges of the user role.
This test would suggest if I set up an API Key as an administrator, any workflow using that key via the python api can conduct any action on my site regardless of the privileges in the key. Obviously that is not great.
Tested this again. Perhaps it is simpler to ask "Is Item Access under Item Privileges for an API Key supposed to limit access to only checked items?" With a test user account, on ArcGIS Online (not Enterprise), a new API Key was created and given item access to one of the users 3 items. However, the key enabled access all the users private items. That is not my understanding of how the key should work. I ran this test using the Rest API with :
import requests
API_KEY = "MY KEY"
url = "https://www.arcgis.com/sharing/rest/search"
params = {
"q": "orgid:MY ORG ID",
"f": "json",
"num": 100,
"token": API_KEY,
}
response = requests.get(url, params=params)
data = response.json()
print(f"Total items visible to key: {data.get('total', 0)}")
I repeated the query using the client id and secret to generate a token, and got the same results as the API Key query. @John-Foster and @Noah-Sager you both have provided input on other API Key posts so hoping perhaps you can help me understand the intent here.