【问题标题】:Azure Active Directory with .Net Core带有 .Net Core 的 Azure Active Directory
【发布时间】:2019-04-18 15:34:40
【问题描述】:

Microsoft 默认标识不符合我的项目需求,因此我不得不编写一个自定义过滤器来处理身份验证。我确实允许用户使用 Azure Active Directory,方法是在我的系统中存储一个带有 ActiveDirectory 用户 ID 及其用户 ID 的引用表。

我真的不得不修改一些东西才能使其在常规 .NET 中工作。我现在已经将我的系统切换到 .Net Core web api Mvc 并且我的许多库和语法没有翻译。

以下代码示例:

public void SignIn() {
 HttpContext.GetOwinContext().Authentication.Challenge(new 
 AuthenticationProperties { RedirectUri = "/" }, 
 OpenIdConnectAuthenticationDefaults.AuthenticationType);
}

我只想引用 azure AD,我可以使用 .net core 登录用户,但无法获取有关用户的任何详细信息。我过去使用的是 azure graph。

如果不使用 Microsoft 标识,我该如何做到这一点?

【问题讨论】:

    标签: c# asp.net-core-mvc owin


    【解决方案1】:

    您的情况不清楚。如果要使用 AAD 实现身份验证,最简单的方法是使用默认的 Azure AD 模板:Change Authentication --> Work or School Accounts。或者手动添加Microsoft.AspNetCore.Authentication.AzureAD.UI 包:

    https://stackoverflow.com/a/54546245/5751404

    如果您使用 .Net Core Web API 作为服务,客户端应向 AAD 请求访问令牌以访问您的受保护 API,您可以使用 JWT 不记名身份验证中间件:

    https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-openidconnect-aspnetcore

    【讨论】:

      猜你喜欢
      • 2017-10-31
      • 1970-01-01
      • 1970-01-01
      • 2017-09-05
      • 2021-10-28
      • 2023-03-11
      • 2018-08-26
      • 1970-01-01
      • 2020-11-11
      相关资源
      最近更新 更多