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

前端 未结 2 600
终归单人心
终归单人心 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.

提交回复
热议问题