我正在使用 IdentityServer4 ,并且需要进行外部身份验证。我需要从idp中获取个人资料和电子邮件声明,并且能够使用Google,Facebook和MS Live ID来做到这一点。但是,我无法在Yahoo中获得电子邮件声明。
在我的Yahoo API应用中,我为个人资料(社交目录)指定 API权限,并选择了 读/写公共和私有
在IdentityServer4应用中,我指定了范围,以包括 sdpp-w ,据称应包含此documentation中所述的电子邮件地址作为附加声明。
这是我的代码的片段:
Startup.cs
services.AddAuthentication()
.AddGoogle(options =>
{
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.ClientId = Configuration.GetValue<string>("ExternalProviders:GoogleClientId");
options.ClientSecret = Configuration.GetValue<string>("ExternalProviders:GoogleSecretKey");
})
.AddFacebook(options =>
{
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.AppId = Configuration.GetValue<string>("ExternalProviders:FacebookAppId");
options.AppSecret = Configuration.GetValue<string>("ExternalProviders:FacebookSecretKey");
options.CallbackPath = Configuration.GetValue<string>("ExternalProviders:FacebookCallbackPath");
})
.AddMicrosoftAccount("Microsoft", "Windows Live ID", options =>
{
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.ClientId = Configuration.GetValue<string>("ExternalProviders:WindowsClientId");
options.ClientSecret = Configuration.GetValue<string>("ExternalProviders:WindowsSecretKey");
options.CallbackPath = Configuration.GetValue<string>("ExternalProviders:WindowsCallbackPath");
})
.AddYahoo(options =>
{
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.Scope.Add("openid,sdpp-w");
options.ClientId = Configuration.GetValue<string>("ExternalProviders:YahooClientId");
options.ClientSecret = Configuration.GetValue<string>("ExternalProviders:YahooSecretKey");
options.CallbackPath = Configuration.GetValue<string>("ExternalProviders:YahooCallbackPath");
});
Config.cs
// scopes define the resources in your system
public static IEnumerable<IdentityResource> GetIdentityResources()
{
return new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
new IdentityResources.Email()
};
}
// clients want to access resources (aka scopes)
public static IEnumerable<Client> GetClients()
{
// client credentials client
return new List<Client>
{
new Client
{
ClientId = "mvc.manual",
ClientName = "MVC Manual Client",
AllowedGrantTypes = GrantTypes.Hybrid,
AllowAccessTokensViaBrowser = true,
ClientSecrets =
{
new Secret("secret".Sha256())
},
RedirectUris = { "https://mywebsite/account/signin-callback" },
PostLogoutRedirectUris = { "https://mywebsite/signout-callback" },
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
"api2"
},
AllowOfflineAccess = true
}
};
}