Get E-mail of User Authenticated with Microsoft Account in ASP.NET Identity

前端 未结 2 599
终归单人心
终归单人心 2021-01-04 14:32

I\'m using the ASP.NET Identity stuff that came with the new MVC 5 templates in VS2013. I\'ve configured external login providers so people can sign up using Google, Faceboo

相关标签:
2条回答
  • 2021-01-04 15:09
    1. Configure the scopes for 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. Grab the email claim

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

    Hope this helps you.

    0 讨论(0)
  • 2021-01-04 15:10
    app.UseMicrosoftAccountAuthentication(new   MicrosoftAccountAuthenticationOptions()
            {
                ClientId = "Your_client_id",
                ClientSecret = "your_client_secret_key",
                Scope = { "wl.basic", "wl.emails" }
            });
    

    and to get email

     var externalIdentity = HttpContext.GetOwinContext().Authentication.GetExternalLoginInfoAsync();
    
    string email=externalIdentity.Result.Email;
    
    0 讨论(0)
提交回复
热议问题