在IdentityServer4中配置多个Oidc提供程序可以通过以下步骤完成:
services.AddIdentityServer()
.AddInMemoryClients(new List<Client>
{
new Client
{
ClientId = "client1",
ClientSecrets = { new Secret("secret1".Sha256()) },
AllowedGrantTypes = GrantTypes.Code,
RedirectUris = { "https://client1/callback" },
PostLogoutRedirectUris = { "https://client1/logout" },
AllowedScopes = { "openid", "profile", "email" },
RequireConsent = false
},
new Client
{
ClientId = "client2",
ClientSecrets = { new Secret("secret2".Sha256()) },
AllowedGrantTypes = GrantTypes.Code,
RedirectUris = { "https://client2/callback" },
PostLogoutRedirectUris = { "https://client2/logout" },
AllowedScopes = { "openid", "profile" },
RequireConsent = false
}
})
.AddInMemoryIdentityResources(new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
new IdentityResources.Email()
})
.AddInMemoryApiResources(new List<ApiResource>())
.AddInMemoryApiScopes(new List<ApiScope>());
app.UseIdentityServer();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapGet("/.well-known/openid-configuration", async context =>
{
var discoveryDocument = new DiscoveryDocumentResponse
{
Issuer = "https://identityserver",
AuthorizationEndpoint = "https://identityserver/connect/authorize",
TokenEndpoint = "https://identityserver/connect/token",
UserInfoEndpoint = "https://identityserver/connect/userinfo",
EndSessionEndpoint = "https://identityserver/connect/endsession",
JwksUri = "https://identityserver/.well-known/jwks"
};
await context.Response.WriteAsJsonAsync(discoveryDocument);
});
});
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://identityserver";
options.ClientId = "client1";
options.ClientSecret = "secret1";
options.ResponseType = "code";
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("email");
options.SaveTokens = true;
});
以上是在IdentityServer4中配置多个Oidc提供程序的基本步骤。根据实际需求,可以根据以上示例进行配置的修改和扩展。关于IdentityServer4的更多详细信息和配置选项,可以参考腾讯云的IdentityServer4文档。
领取专属 10元无门槛券
手把手带您无忧上云