This is the code which I tried, I am hiding the critical info with 'xxx'
client_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
tenant = 'xxx'
tenant_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
client_id = client_id + '@' + tenant_id
data = { 'grant_type':'client_credentials', 'resource': "00000003-0000-0ff1-ce00-000000000000/" + tenant + "xxx.sharepoint.com@" + tenant_id, 'client_id': client_id, 'client_secret': client_secret,}
headers = { 'Content-Type':'application/x-www-form-urlencoded' }
url = "https://accounts.accesscontrol.windows.net/tenant_id/tokens/OAuth/2" r = requests.post(url, data=data, headers=headers) json_data = json.loads(r.text) print(json_data)
Can anyone guide me on this. This is the first time I am doing this. Have no clue how to debug it and what is causing this error.
This is the error message.
{'error': 'invalid_request', 'error_description': "AADSTS900023: Specified tenant identifier 'tenant_id' is neither a valid DNS name, nor a valid external domain.\r\nTrace ID: 20f02c71-c802-467a-a3fe-0b45a08e4c00\r\nCorrelation ID: 03f90547-f507-4595-85a6-003c6e658171\r\nTimestamp: 2023-08-01 09:09:56Z", 'error_codes': [900023], 'timestamp': '2023-08-01 09:09:56Z', 'trace_id': '20f02c71-c802-467a-a3fe-0b45a08e4c00', 'correlation_id': '03f90547-f507-4595-85a6-003c6e658171', 'error_uri': 'https://accounts.accesscontrol.windows.net/error?code=900023'}