Last active
July 4, 2024 13:15
-
-
Save Rajchowdhury420/acc7da3ceb71fae78efecec0a4048256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
base_url = 'https://vgtpt.cyberark.cloud/PasswordVault/WebServices/PIMServices.svc/Applications/' | |
username = 'your_username' | |
password = 'your_password' | |
auth_url = f'{base_url}API/auth/ldap' | |
# Authenticate and get token | |
auth_payload = { | |
'username': username, | |
'password': password | |
} | |
auth_response = requests.post(auth_url, data=auth_payload) | |
print('Raw authentication response content:') | |
print(auth_response.text) | |
if auth_response.status_code == 200: | |
try: | |
token = auth_response.json()['token'] | |
print('Authentication successful') | |
except ValueError: | |
print('Failed to decode JSON response') | |
print(auth_response.text) | |
exit() | |
else: | |
print('Authentication failed') | |
print(auth_response.text) | |
exit() | |
list_users_url = f'{base_url}Users' | |
headers = { | |
'Authorization': f'Bearer {token}' | |
} | |
response = requests.get(list_users_url, headers=headers) | |
print('Raw user list response content:') | |
print(response.text) | |
if response.status_code == 200: | |
try: | |
users = response.json() | |
for user in users: | |
print(user) | |
except ValueError: | |
print('Failed to decode JSON response') | |
print(response.text) | |
else: | |
print('Failed to retrieve users') | |
print(response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment