Thanks ZHU,
However, I'm not trying to authenticate with Business Central using a Power Platform connector. Rather, I'm trying to connect via an HTTPS request in a python script. An example of the code I'm using is below.
from azure.identity import DefaultAzureCredential
import requests
from requests.auth import AuthBase
class BearerTokenAuth(AuthBase):
def __init__(self, token):
self.token = token
def __call__(self, r):
r.headers["Authorization"] = f"Bearer {self.token}"
return r
# Set up Azure credentials
credential = DefaultAzureCredential(
managed_identity_client_id="<client_id>",
workload_identity_tenant_id="<tenant_id>",
)
# Define the required scope for Business Central API
bc_scope = "https://api.businesscentral.dynamics.com/.default"
# Get the authentication token
token = credential.get_token(bc_scope).token
# Define the API endpoint
endpoint = "https://api.businesscentral.dynamics.com/environments/v1.1"
# Initialize authentication handler
auth = BearerTokenAuth(token)
# Make the API request
response = requests.get(endpoint, auth=auth)