简体   繁体   English

授权 Dynamics 365 Business Central API

[英]Authorize Dynamics 365 Business Central API

I want to create a Webjob that is supposed to run on a schedule.我想创建一个应该按计划运行的 Webjob。 The Purpose of the webjob is basically to check some database tables and create item(s) in Dynamics 365 BC accordingly if there are new entries in the tables. Webjob 的目的基本上是检查一些数据库表,如果表中有新条目,则相应地在 Dynamics 365 BC 中创建项目。 While designing an approach to achieve all this, the first step is to authenticate the API, so we could make POST Calls.在设计实现所有这些的方法时,第一步是验证 API,以便我们可以进行POST调用。 The document here specifies different API endpoints which have their respective authentication mechanisms ie via Azure Active Directory ( requires an app registeration with Delegated permissions for Dynamics Business Central API) or Basic Authentication. 此处的文档指定了不同的 API 端点,它们具有各自的身份验证机制,即通过 Azure Active Directory(需要具有 Dynamics Business Central API 的Delegated权限的应用程序注册)或基本身份验证。 I know, we can get Access token from Azure active directory using client id and secret by:我知道,我们可以使用客户端 ID 和密码从 Azure 活动目录获取访问令牌:

ClientCredential clientCredential = new ClientCredential(clientId, clientSecret);
var authenticationContext = new AuthenticationContext(authorityUri, true);
AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(resource, clientCredential).GetAwaiter().GetResult();
accessToken = authenticationResult.AccessToken;

Now, Since my web job needs to run at the back-end without any user interaction so, Azure AD authentication doesn't fit here as it requires user interaction to consent.现在,由于我的 web 作业需要在后端运行而无需任何用户交互,因此 Azure AD 身份验证不适合此处,因为它需要用户交互才能同意。 Whereas Basic authentication is not recommended for production scenarios.而基本认证不推荐用于生产场景。
Please suggest how access token should be generated so it doesn't require user interaction.请建议应该如何生成访问令牌,以便它不需要用户交互。

EDIT编辑

Per Allen's reply, basic authentication can be used for this scenario although Microsoft documents need to be updated to support this scenario.根据 Allen 的回复,基本身份验证可用于此场景,但需要更新 Microsoft 文档以支持此场景。 But, while exploring API endpoint https://api.businesscentral.dynamics.com/v1.0/<mydomain.com>/api/beta/companies using Postman and basic authentication, I am facing the following error:但是,在探索 API 端点https://api.businesscentral.dynamics.com/v1.0/<mydomain.com>/api/beta/companies使用 Z6F061E1CAD5E2783CEA0B2976ED2F4C 时,我面临以下身份验证错误:

{
    "error": {
        "code": "Authentication_InvalidCredentials",
        "message": "The server has rejected the client credentials.  CorrelationId:  641ea3fd-19d6-4402-8e68-a70145eb6da3."
    }
}

While i have generated webservice access key for my business central user and using that alongwith the username for basic authentication.虽然我为我的业务中心用户生成了 Web 服务访问密钥,并将其与用户名一起用于基本身份验证。 I am sure that i am copying the correct webservice key.我确信我正在复制正确的网络服务密钥。 Any help will be highly appreciated.任何帮助将不胜感激。

The supported Authentication methods for Dynamics 365 BC are only these 2 options based on the official document :根据官方文档,Dynamics 365 BC 支持的身份验证方法只有这 2 个选项:

  • Basis Authentication基础认证
  • AAD authentication AAD 身份验证

Basis Authentication is for none user interaction while AAD authentication is for user interaction.基本身份验证用于无用户交互,而 AAD 身份验证用于用户交互。

So in your scenario AAD authentication has been Excluded, the only choice is Basis Authentication, which is for Application-only permission.因此,在您的场景中,AAD 身份验证已被排除,唯一的选择是基本身份验证,它适用于仅限应用程序的权限。

Although Basis Authentication is not recommended, you have to use it to meet your requirement currently.虽然不推荐使用基本身份验证,但您必须使用它来满足您当前的要求。

And based on this post in Dynamics 365 Business Central Forum, @Stefano Demiliani has said that Basic Authentication can be used in a production environment, it only depends on your choice.根据 Dynamics 365 Business Central 论坛中的这篇帖子,@Stefano Demiliani 表示基本身份验证可用于生产环境,这仅取决于您的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM