这是我的 MSAL 身份验证:
@app.route('/get-microsoft-data', methods=('GET', 'POST'))
def get_microsoft_token():
public_app = ConfidentialClientApplication(
client_id="<client_id>", authority="https://login.microsoftonline.com/<tenant_id>",
client_credential="<client_secret>"
)
result = None
result = public_app.acquire_token_silent(["https://api.businesscentral.dynamics.com/.default"], account=None)
if not result:
print("No suitable token exists in cache. Let's get a new one from AAD.")
result = public_app.acquire_token_for_client(scopes=["https://api.businesscentral.dynamics.com/.default"])
if "access_token" in result:
global microsoft_token
microsoft_token = result["access_token"]
return redirect('/')
这是我对业务中心 API 的调用:
@app.route('/send-data-to-microsoft', methods=('GET', 'POST'))
def send_data_to_microsoft():
print(microsoft_token)
headers = {
"Authorization": "Bearer " + microsoft_token
}
r = requests.get("https://api.businesscentral.dynamics.com/v1.0/<tenant_domain>/sandbox/api/v1.0/companies", headers=headers)
print(r.json())
return redirect('/')
这是我在调用 /send-data-to-microsoft 时遇到的错误:
{'error': {'code': 'Authentication_InvalidCredentials', 'message': 'The server has rejected the client credentials. CorrelationId: ff4d9d32-db03-4c2a-bf77-2e6186d4988c.'}}
这是我想要的文档:https ://docs.microsoft.com/en-us/dynamics-nav/api-reference/v1.0/api/dynamics_companies_get
这是业务中心的有效端点列表:https ://docs.microsoft.com/en-us/dynamics-nav/api-reference/v1.0/endpoints-apis-for-dynamics