Skip to content

Instantly share code, notes, and snippets.

@recklessop
Created September 1, 2023 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recklessop/94cdd3edd4779aee1d2de0e5493d3939 to your computer and use it in GitHub Desktop.
Save recklessop/94cdd3edd4779aee1d2de0e5493d3939 to your computer and use it in GitHub Desktop.
import requests
base_server = "192.168.50.60"
keycloak_base_url = f"https://{base_server}/auth" # Replace with your Keycloak server URL
zvm_api_url = f"https://{base_server}/v1"
realm = "zerto" # Replace with your Keycloak realm name
client_id = "api-script"
client_secret = "fcYMFuA5TkIUwp6b3hDUxim0f32z8erk" # Replace with your client's secret key
token_url = f"{keycloak_base_url}/realms/{realm}/protocol/openid-connect/token"
data = {
"grant_type": "client_credentials",
"client_id": client_id,
"client_secret": client_secret,
}
# Disable SSL certificate verification (use with caution)
response = requests.post(token_url, data=data, verify=False)
if response.status_code == 200:
access_token = response.json()["access_token"]
print("Authentication successful. Access token:", access_token)
else:
print("Authentication failed. Status code:", response.status_code)
print("Error message:", response.text)
uri = zvm_api_url + "/vpgs"
print(uri)
headers = {
"Authorization": f"Bearer {access_token}",
"accept": "application/json"
}
# Make a POST request to the token URL with the data headers=headers,
response = requests.get(uri, headers=headers, verify=False)
# Check if the request was successful (HTTP status code 200)
if response.status_code == 200:
# Parse the response JSON to get the access token
print(response.text)
else:
print("Status code:", response.status_code)
print("Error message:", response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment