- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已尽可能密切地关注 AzureAD aspnetcore 示例,以尝试在我们的 aspnetcore 2.2 webapp 中实现 Azure AD 身份验证。我能够使用 Azure AD 成功登录。但是,登录后不会显示用户名。
https://github.com/Azure-Samples/active-directory-b2c-dotnetcore-webapp
应在 View 中从 User.Identity.Name 属性中读取此值。
在进一步检查中,我可以看到主 claim 已正确返回到应用程序。但是,由于某种原因,HttpContext.User 对象未正确填充。我不知道为什么会这样。当我查看上面示例中的相同值时,HttpContext 已正确设置。为了澄清起见,我已经实现了 OnSecurityTokenValidated 处理程序并且我使用了这个上下文:
可以看出,userPrincipal 具有预期的声明。
但是,httpContext 没有声明。因此 User.Identity.Name 也为空:
我已经尝试执行手动登录,但这也不起作用:
private async Task SignInUser(TokenValidatedContext tokenValidatedContext)
{
var httpContext = tokenValidatedContext.HttpContext;
var userPrincipal = tokenValidatedContext.Principal;
await httpContext.SignOutAsync(AppSettings.CookieName);
await httpContext.SignInAsync(AppSettings.CookieName, userPrincipal,
new AuthenticationProperties
{
ExpiresUtc = DateTime.UtcNow.AddDays(1),
IsPersistent = false,
AllowRefresh = false
});
}
更新
我正在设置 NameClaimType,如上所示。 NameClaimType 在Configure 中设置
有人知道我做错了什么吗?
我正在使用 Visual Studio 2017 和 aspnetcore 2.2 库。我已将 Microsoft.Identity.Client 升级到 2.7
最佳答案
您是否在OpenIdConnectOptions
配置中设置了NameClaimType
:
options.TokenValidationParameters = new TokenValidationParameters() { NameClaimType = "name" };
为了测试场景,我使用默认 MVC 模板创建了一个新的 asp.net core 2.2 应用程序:
MSALSessionCache
、AzureAdB2COptions
、OpenIdConnectOptionsSetup
Startup.cs
和appsettings.json
。 我没有创建自己的应用程序和 Api,只是使用代码示例提供的 fabrikamb2c
domain,即使某些方法在 .net core 2.2 中已过时,例如 cache。已更改
。身份验证仍然有效,并使用 User.Identity.Name
获得正确的名称,还设置了 HttpContext.User.Claims
:
您可以提供更多详细信息以帮助重现您的问题。
关于c# - 使用 aspnetcore 2.2 联合 Azure AD 登录后,User.Identity.Name 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54444747/
我有一个场景,我们必须通过 Azure AD 对企业用户进行身份验证,但通过 Azure AD B2C 对外部用户进行身份验证——所有这些都来自同一个登录屏幕。 有一些 Web 应用程序将共享此功能。
在使用 Azure AD B2C 和 Azure AD B2B 之前,我通常会将应用程序添加到我们租户的 Azure AD 中,并且 Office 365 用户可以使用其帐户 (SSO) 访问应用程序
当 Azure Active Directory 信任访问本地 Active Directory 用户时,我们是否可以使用本地 AD 用户名(域限定的 sam 帐户名称,例如:cosmos\brahm
什么是在网站上展示广告的好托管广告管理器? 我听说过OpenX ,但从未使用过。 最佳答案 我们使用名为 Ad Serving Solutions http://www.adservingsoluti
是否可以将用户从云 Azure Active Directory 同步到本地 AD? On Premises 这里有点错误,因为它实际上是 Azure 中的虚拟网络,带有 Windows Server
我正在关注这里的答案:Multi-Tenant Azure AD Auth in Azure AD B2C with Custom Policies 以及这里的演练:https://github.co
我正在尝试使用/common Azure AD 端点在 Azure AD B2C 中使用 Azure AD Auth。根据How to sign in any Azure Active Directo
来自 Mercurial 文档: The manifest is the file that describes the contents of the repository at a particu
我正在尝试将 firebase admob 与 React Native 集成到我的应用程序中,一切都适用于 testID横幅 ('ca-app-pub-3940256099942544/293473
我有一个应用程序需要根据其本地 AD 通用名称来过滤权限。几点注意事项: Azure AD Connect 正在 OnPrem AD 和 Azure 之间同步数据 我已成功将登录用户的组信息从 Azu
我正在使用 blogspot 平台并在我的网站上使用了 Google Adsense。我想对齐一个自动 Adsense 广告,它根本不居中,而带有代码的广告则完全没有问题。它只是自动广告,有人可以帮助
为什么redirect URL必须完全匹配?在域级别进行匹配是否不足以提供适当的安全性? 如果我有数百条路径怎么办? 示例网址: https://myawesomesite.com https://m
我即将创建一个新的 Azure AKS 群集,并且希望将 AKS 与 Azure Key Vault 集成。几个月前,在学习阶段,我看到需要使用Azure AD pod管理的身份来做到这一点,但现在我
我正在尝试配置我的 Azure AD 以同步我的本地 AD DS,如果在 Microsoft Azure AD 中添加任何用户,它应该自动在我的本地 AD 中注册。 我已创建 Azure AD 并配置
我有大约 50 个用户的 Azure AD。这些用户是我们购买Office365时创建的。假设 Azure AD 上的域是 example.com。 ([email protected])在本地,我们
我正在尝试获取组 Azure AD 的名称,Azure 登录 (openId) 后的内部 token 我收到 json 格式的组 ID,但我需要组名称。 登录后的Json: Claims 尝试使用Gr
我们希望将 Azure AD B2C 用于我们的 Web 应用程序,以允许用户使用其公司 ADFS 帐户登录。 根据Azure Active Directory B2C: Add ADFS as a
首先,我无法了解为什么需要这些数据,也无法了解有关网络的细节。您必须相信我,除了运行 LDAP 查询的 PowerShell 脚本之外,没有其他方法可以获取这些数据。 我正在使用具有多个林和多个域的网
我是一个相当新的 PS 用户...正在寻求有关 powershell 脚本的帮助来获取用户所属的安全组列表。 描述我需要什么: 我有包含许多用户(samaccountnames)的输入列表(txt 文
我有两个要存储在目录中以供我的应用程序使用的声明。这些内容不可供用户编辑,但可用于应用程序从 token 中读取。 内置策略可以检索声明,但是,使用自定义策略检索这些声明没有取得任何成功。 通读文章“
我是一名优秀的程序员,十分优秀!