使用 Azure Active Directory 以编程方式对 .net core 2 API 中的用户进行身份验证的最佳方法是什么

What's the best way to authenticate a user in a .net core 2 API programatically using Azure Active Directory

我正在开发一个具有 angular 6 前端和 .net core 2.0 后端的应用程序,我正在尝试对其进行设置,以便我的应用程序通过 Azure 活动目录对用户进行身份验证。问题是当我让前端传递电子邮件和密码时,我希望 .net 核心后端以编程方式进行所有身份验证。到目前为止,我在网上看到的所有内容都建议将前端重定向到 Microsoft 登录页面,但我们将我们的应用程序用作样板项目,并希望能够在后端轻松更改身份验证类型,而无需必须更改 angular 前端。有谁知道我该怎么做?

您可以使用Resource Owner Password Credentials Grant。该过程将希望您在Angular app 和post 中收集用户凭据到.net core 后端,然后在back-end 带有用户凭据的应用程序。但不推荐,因为 ROPC 流程需要高度信任和用户曝光,您应该仅在无法使用其他更安全的流程时才使用此流程。

还有:

  • The Microsoft identity platform endpoint only supports ROPC for Azure AD tenants, not personal accounts. This means that you must use a tenant-specific endpoint (https://login.microsoftonline.com/{TenantId_or_Name}) or the organizations endpoint.
  • Personal accounts that are invited to an Azure AD tenant can't use ROPC.
  • Accounts that don't have passwords can't sign in through ROPC. For this scenario, we recommend that you use a different flow for your app instead.
  • If users need to use multi-factor authentication (MFA) to log in to the application, they will be blocked instead.

参考:https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc