I want to have access to the apis of this swagger file: https://flightclaims-dev.azurewebsites.net/swagger/index.html
But with the following code I ran into 401 error:
`
from azure.identity import ClientSecretCredential
import requests
# Azure AD configuration
TENANT_ID = 'xxx'
CLIENT_ID = 'xxx'
CLIENT_SECRET = 'xxx'
# Delegated scopes required for Microsoft Graph API access
SCOPES = ['User.Read'] # Example scopes
# Initialize the Azure Identity client with client secret credential
credential = ClientSecretCredential(
tenant_id=TENANT_ID,
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET
)
# Obtain an access token for Microsoft Graph API with delegated permissions
token_data = credential.get_token("https://graph.microsoft.com/.default", scopes=SCOPES)
access_token = token_data.token
print(token_data)
# Microsoft Graph API endpoint
graph_api_endpoint = 'https://flightclaims-dev.azurewebsites.net/api/ApplicationParameter'
# Set headers with Authorization token
headers = {
'Authorization': 'Bearer ' + access_token
}
try:
# Make a GET request to Microsoft Graph API endpoint with headers
response = requests.get(graph_api_endpoint, headers=headers)
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Print the response data
print(response.json())
else:
# Print error message if request was not successful
print(f'nFailed to retrieve data. Status code: {response.status_code}')
print(response.text) # Print error response if needed
except requests.exceptions.RequestException as e:
# Print error message if an exception occurs during the request
print(f'An error occurred: {e}')
`
The token that I get is correct by the way
I probably need to change my Azure API permissions but I don’t know how?