这是我的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('/')
这是我对business central 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('/')
这就是我在调用/向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
这是business central的有效终结点列表:https://docs.microsoft.com/en-us/dynamics-nav/api-reference/v1.0/endpoints-apis-for-dynamics
2021-10-12更新:BC现在支持客户端凭据流
需要进行一些额外的设置。以下链接将引导您浏览:
https://www.kauffmann.nl/2021/07/06/service-to-service-authentication-in-business-central-18-3-how-to-set-up/
归结起来是:
此时,您可以通过以下方式获得令牌:
客户查询的作用如下:
顺便说一句,我得到了相同的
Authentication_InvalidCredentials
错误,结果它与BC中的外部应用程序绑定在一起,但没有激活此处不支持客户端凭据流。Dynamics 365 BC支持的身份验证方法仅包括以下两个基于官方文档的选项:
如果希望使用不需要用户交互的方法调用D365 BC API,则应选择Basis Authentication
具体步骤如下:
然后你可以引用Exploring the APIs with Postman and basic authentication
相关问题 更多 >
编程相关推荐