asp.net-mvc - Azure AD Identity 似乎没有提供用于自动链接 Umbraco 用户的电子邮件

标签 asp.net-mvc azure active-directory umbraco azure-active-directory

我已经设置了 Azure Active Directory 身份验证配置,并且通过我们的 Azure AD 登录运行良好。

我已经修改了 AuthenticationOptions,以便外部登录自动链接帐户,但 Azure AD 似乎没有提供要链接的电子邮件地址。

adOptions.SetExternalSignInAutoLinkOptions(new ExternalSignInAutoLinkOptions(
            autoLinkExternalAccount:true));

它给了我以下异常

The requested provider (https://sts.windows.net/{id}) has not provided an email address, the account cannot be linked.

有办法让这个工作成功吗?无需 SetExternalSignInAutoLinkOptions 设置即可完美运行。

最佳答案

事实证明,Name 声明也是电子邮件地址,因此我必须拦截通知以将 Name 声明作为 Email 传递 声明:

adOptions.Notifications = new OpenIdConnectAuthenticationNotifications()
        {
            SecurityTokenValidated = async n =>
            {
                var id = n.AuthenticationTicket.Identity;

                var nid = new ClaimsIdentity(
                    id.AuthenticationType,
                    System.Security.Claims.ClaimTypes.GivenName,
                    System.Security.Claims.ClaimTypes.Role);

                //Here I added the Name as E-mail claim
                nid.AddClaim(new Claim(ClaimTypes.Email, id.Name));
                nid.AddClaim(id.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier));
                nid.AddClaim(id.FindFirst(System.Security.Claims.ClaimTypes.GivenName));
                nid.AddClaim(id.FindFirst(System.Security.Claims.ClaimTypes.Name));

                n.AuthenticationTicket = new AuthenticationTicket(nid, n.AuthenticationTicket.Properties);
            }
        };

关于asp.net-mvc - Azure AD Identity 似乎没有提供用于自动链接 Umbraco 用户的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40301349/

相关文章:

.net - 如何将 css class 属性添加到 razor 中的文本框?

azure - 使用连接字符串在 Azure 中进行身份验证

php - 为傻瓜安全连接到 ldap

c# - 如何知道我的 DirectoryEntry 是否真的连接到我的 LDAP 目录?

asp.net-mvc - 通过路由的 ASP.NET MVC 博客 URL

c# - 为什么我的动态样式表 url 在 MVC 中不起作用?

asp.net-mvc - 测试方法中的 Moq Automapper 服务在映射时返回 null

postgresql - 从 Azure CLI(不是 ARC)创建 PostgreSQL 超大规模 Citus DB

azure - 在文件共享中复制文件时出现 Azure 数据工厂配置问题

web-services - 如何改进 Perl Dancer 应用程序中的身份验证