get_public_api_client(client_id, client_secret, app_name_header, on_behalf_of_header, client_type_header):
"""
Description
-----------
Method 1, To get the client object of QDC Api using client id and client secret.
Args
----
client_id: Please request client id by contacting QDC Support.
client_secret: Please request client id by contacting QDC Support.
app_name_header: Name of the Client.
on_behalf_of_header: Name of the user who is initiating the request.
client_type_header: Client code type connecting to QDC Api.
Returns
-------
object: Authenticated client object.
None: In case of an failure.
Usages
------
# Please request client id/secret through QDC team
client_id = ""
client_secret = ""
appname = "ai hub"
on_behalf_of = "user_name"
client_type = "Python"
# qdc_api is the name of the module
public_api_client = qdc_api.get_public_api_client(client_id, client_secret, appname, on_behalf_of, client_type)
"""
response = requests.post(ACCESS_TOKEN_URL, auth=(client_id, client_secret))
if response.status_code == 200:
token = json.loads(response.text)["access_token"]
print(f"Token acquired: {token}")
else:
print(f"Failed to acquire token: {response.text}")
exit()
qdc_headers = {
"X-QCOM-TokenType": "OAuth",
"X-QCOM-ClientId": client_id,
"X-QCOM-AppName": app_name_header,
"X-QCOM-OnBehalfOf": on_behalf_of_header,
"X-QCOM-ClientType": client_type_header,
}
return AuthenticatedClient(base_url=API_BASE_URL, headers=qdc_headers, token=token)