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

Azure AD Identity doesn't seem to provide email for auto-linking Umbraco User

我已经设置了 Azure Active Directory 身份验证配置,并且通过我们的 Azure AD 登录非常有效。

我已经修改了 AuthenticationOptions,因此外部登录会自动 link 登录帐户,但 Azure AD 似乎没有向 link 提供电子邮件地址。

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 设置的情况下工作得很好。

根据描述,您似乎希望令牌端点发出 email 声明。

据我所知,Azure AD V2.0 通过使用 email 范围支持此声明。可以参考一下here. However, based on the test, it only support for the Microsoft Account at present. If you also want it to support the work or school account, you may submit the feedback from here.

原来 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);
            }
        };

我遇到了同样的问题,你可以进入 Azure 门户并在

Azure Active Direction -> 应用注册 -> 你的应用

Select 令牌配置和“添加可选声明”select “ID”和“电子邮件”和“添加”

然后 returns 电子邮件作为令牌的一部分。