0 votes
#!/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

by (40 points)

1 Answer

0 votes
by (14.5k points)

Hello,

In the provided script, in the request to get group members, you are using the token obtained from the request used to create a new session. However, you additionally need to obtain a security token and then use it in the get group members request. For details and examples on how to authenticate with Adaxes REST API, please, have a look at the following SDK article: https://www.adaxes.com/sdk/REST_Authentication. Also, you can find an example of the full authentication process here: https://www.adaxes.com/sdk/REST_Authentication/#full-authentication-process.

Related questions

0 votes
1 answer

hi Team, I have written the code in python to fetch the members in a given LDAP group using a Adaxes API and Python3. Below is my code. I have sheilded the url and password with ... 26T14:05:59.8180694Z'} must be of type str or bytes, not <class 'dict'>

asked Sep 26, 2022 by udathakarthic (40 points)
0 votes
1 answer

I'm looking to find any Python examples of using the REST API. An Internet search didn't turn anything up.

asked Nov 25, 2021 by swengr59 (60 points)
0 votes
1 answer

Is it possible to add multiple members to a group in a singe call to the REST API? The example code only shows a single member. What would the data structure look like in that case?

asked Dec 13, 2021 by swengr59 (60 points)
0 votes
1 answer

Hi, { "criteria": { "objectTypes": [ { "type": "USER", "items": { "type": 1, "items": [ { "type": 0, "property": "accountDisabled", "operator": "eq" ... ": { "isDisabled": true, Please share the right request JSON to get the required result. Thanks, Lohith

asked Oct 3 by lom (20 points)
0 votes
1 answer

Is this possible? We have a potential use case where we want to "natively" query AD using LDAP, but want to be able to leverage custom attributes\data in Adaxes, ... we can query the LDS instance and access both native and custom attributes etc. Many Thanks

asked May 25, 2017 by firegoblin (1.6k points)
3,571 questions
3,261 answers
8,275 comments
547,988 users