我不确定是否可行,但是我想知道,当注册使用身份服务器的新客户端(我们已经为其定义了外部登录名)时,我们可以限制这些外部提供程序的数量吗?>
例如,一个客户仅支持Facebook,另一个仅支持Twitter?
...或者对于同一身份服务器实例下的所有客户端始终使用相同的外部登录,所以我需要两个单独的身份服务器实例吗?
答案 0 :(得分:1)
您可以使用Client
属性将IdentityProviderRestrictions
配置为支持特定的外部提供程序。此属性包含可用于客户端的提供程序名称的列表。空列表(默认)表示允许所有提供者。
例如
new Client {
ClientId = "yourclient",
ClientName = "Your Client",
.
.
.
IdentityProviderRestrictions = {"Facebook", "Google"};
}
此属性用于在IdentityServer的示例AccountController
中过滤外部提供程序:
if (context?.ClientId != null)
{
var client = await _clientStore.FindEnabledClientByIdAsync(context.ClientId);
if (client != null)
{
allowLocal = client.EnableLocalLogin;
if (client.IdentityProviderRestrictions != null && client.IdentityProviderRestrictions.Any())
{
providers = providers.Where(provider => client.IdentityProviderRestrictions.Contains(provider.AuthenticationScheme)).ToList();
}
}
}
在您的AccountController
中,您可以使用AuthorizationRequest.ClientId
标识发出身份验证请求的客户端。然后,您可以根据发出请求的客户端来更改登录功能。
AuthorizationRequest
获得 IIdentityServerInteractionService.GetAuthorizationContextAsync
,并通过DI获得IIdentityServerInteractionService
。