gpt4 book ai didi

c# - 获取在 ASP.NET Identity 中使用 Microsoft 帐户进行身份验证的用户的电子邮件

转载 作者:可可西里 更新时间:2023-11-01 09:01:09 26 4
gpt4 key购买 nike

我正在使用 VS2013 中新的 MVC 5 模板附带的 ASP.NET Identity。我已经配置了外部登录提供商,因此人们可以使用 Google、Facebook 或 Microsoft 进行注册。但是,我仍然想获取人们的电子邮件地址(例如用于通知、更新等)。

默认情况下,app.UseGoogleAuthentication() 还将请求用户的电子邮件地址。对于 Facebook,我创建了 FacebookAuthenticationOptions 类的新实例,并添加了以下范围:facebook.Scope.Add("email")。这也有效。

我在为使用 Microsoft 帐户的人获取电子邮件时遇到问题。 MicrosoftAccountAuthenticationOptions 也有一个 Scope 属性,但是添加 email 似乎不起作用。在documentation我看到有一个作用域 wl.emails 但它返回一个电子邮件地址数组,我不确定这是否与 Facebook 的 email 等效。

有没有人建议如何在验证时获取电子邮件地址作为声明?

最佳答案

  1. 为 Microsoft 配置范围。

    var mo = new MicrosoftAccountAuthenticationOptions
    {
    Caption = "Live",
    ClientId = clientId,
    ClientSecret = clientSecret,
    };

    mo.Scope.Add("wl.basic");
    mo.Scope.Add("wl.emails");

    app.UseMicrosoftAccountAuthentication(mo);
  2. 获取电子邮件声明

    var identity = await AuthenticationManager.AuthenticateAsync(DefaultAuthenticationTypes.ExternalCookie);
    var emailClaim = identity.Identity.FindFirst(ClaimTypes.Email);

希望对你有帮助。

关于c# - 获取在 ASP.NET Identity 中使用 Microsoft 帐户进行身份验证的用户的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22229593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com