使用Owin.Security.Providers.Yahoo填充电子邮件值

时间:2017-06-01 03:39:21

标签: asp.net-mvc oauth-2.0 owin yahoo-api

我正在使用Yahoo Owin安全提供程序使用Yahoo对我的Web应用程序用户进行身份验证。他们能够正确地进行身份验证,但Email属性始终为null。如何配置此提供程序,以便在调用AuthenticationManager.GetExternalLoginInfoAsync后设置ExternalLoginInfo.Email属性?我的身份验证配置设置如下:

app.UseYahooAuthentication(new YahooAuthenticationOptions
{
    AuthenticationMode = AuthenticationMode.Passive,
    AuthenticationType = "Yahoo",
    BackchannelTimeout = TimeSpan.FromSeconds(60),
    Caption = "Yahoo",
    ConsumerKey = yahooKey,
    ConsumerSecret = yahooSecret,
    Provider = new YahooAuthenticationProvider
    {
        OnAuthenticated = context =>
        {
            foreach (var claim in context.User)
            {
                var claimType = $"urn:yahoo:{claim.Key}";
                var claimValue = claim.Value.ToString();
                if (!context.Identity.HasClaim(claimType, claimValue))
                    context.Identity.AddClaim(new Claim(claimType, claimValue, "XmlSchemaString", "Yahoo"));
            }

            return Task.FromResult(0);
        }
    }
});

}

0 个答案:

没有答案