#!/bin/python3
import requests
import json
baseUrl = "https://xxxxxxxxxx/restApi"
endpoint = "/api/authSessions/create"
# Request parameters
requestUrl = baseUrl + endpoint
requestBody = {
"username": "xxxxxxxxx@ad.xxxxx.com",
"password": "@xxxxxxxxxxx"
}
# Make request
request = requests.post(requestUrl, json=requestBody)
intermediate_token = json.loads(request.content)
token=intermediate_token['sessionId']
print(intermediate_token)
print(token)
endpoint = "/api/directoryObjects/groupMembers"
# Request parameters
requestUrl = baseUrl + endpoint
requestHeaders = {"Adm-Authorization": token }
queryParams = {
"group": "CN=GCS_Admins,OU=Unix/Linux Security,OU=Groups,OU=Olathe,DC=ad,DC=garmin,DC=com",
"includeIndirect": True
}
# Make request
request = requests.get(requestUrl, headers=requestHeaders, params=queryParams)
response = json.loads(request.content)
print(response)
I'm getting the following error when executed.
{'sessionId': 'hQaY0q87s_Rur6taD8pl6zK7QJZiSQ8Ysvz_nRJD', 'totpState': None, 'changePasswordReason': 0, 'expiresAtUtc': '2022-12-26T05:25:20.1767895Z'}
hQaY0q87s_Rur6taD8pl6zK7QJZiSQ8Ysvz_nRJD
{'message': 'The provided authentication token is either expired or invalid.', 'code': 'unauthenticated'}
Could you please suggesst