def get_azure_cloudcheckr_service_principal_id(AzureGraphApiBearerToken, AzureCloudCheckrApplicationName): """ Gets the service principal id Azure Application that was specifically created for CloudCheckr. Note: This is not the application id. The service principal id is required for the role assignment. This uses the microsoft Graph API. https://docs.microsoft.com/en-us/graph/api/serviceprincipal-list?view=graph-rest-1.0&tabs=http """ api_url = "https://graph.microsoft.com/v1.0/servicePrincipals?$filter=displayName eq '" + AzureCloudCheckrApplicationName + "'" authorization_value = "Bearer " + AzureGraphApiBearerToken response = requests.get(api_url, headers={"Authorization": authorization_value}) if "value" in response.json(): value = (response.json()["value"])[0] if ("id" in value) and ("appId" in value): return value["id"], value["appId"] print("Failed to get the Azure CloudCheckr Application Service principal Id") return None