使用IdentityServer4作为认证服务提供程序,并使用Angular Oauth2 OIDC作为客户端应用程序的身份验证库。这将允许每个客户端应用程序使用独立的登录。
配置IdentityServer4以允许多个客户端应用程序使用相同的身份验证资源。这可以通过在IdentityServer4配置文件中指定多个客户端应用程序进行完成。例如:
public static IEnumerable Clients =>
new List
{
new Client
{
ClientId = "myFirstClient",
ClientName = "My First Client",
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets =
{
new Secret("mySecret".Sha256())
},
AllowedScopes = { "api1", "api2" }
},
new Client
{
ClientId = "mySecondClient",
ClientName = "My Second Client",
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets =
{
new Secret("mySecret".Sha256())
},
AllowedScopes = { "api1", "api3" }
}
};
在Angular中,使用Angular Oauth2 OIDC库并使用不同的ClientId来初始化每个客户端应用程序的身份验证服务。例如:
const myFirstClientConfig = {
clientId: 'myFirstClient',
scope: 'openid profile email',
issuer: 'http://localhost:5000',
redirectUri: 'http://localhost:4200/callback',
silentRedirectUri: 'http://localhost:4200/silent-refresh.html',
tokenEndpoint: 'http://localhost:5000/connect/token',
userinfoEndpoint: 'http://localhost:5000/connect/userinfo',
oidc: false,
showDebugInformation: true
};
const mySecondClientConfig = {
clientId: 'mySecondClient',
scope: 'openid profile email',
issuer: 'http://localhost:5000',
redirectUri: 'http://localhost:4200