首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在IdentityServer4中配置多个Oidc提供程序

在IdentityServer4中配置多个Oidc提供程序可以通过以下步骤完成:

  1. 添加Oidc提供程序的配置:在IdentityServer的配置文件中,添加每个Oidc提供程序的配置。配置包括提供程序的名称、客户端ID、客户端密钥、授权终结点、令牌终结点等信息。例如:
代码语言:txt
复制
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>());
  1. 配置IdentityServer的端点:在Startup类的Configure方法中,配置IdentityServer的端点。例如:
代码语言:txt
复制
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);
    });
});
  1. 配置客户端应用程序:在客户端应用程序中,配置每个Oidc提供程序的选项。选项包括提供程序的授权终结点、令牌终结点、客户端ID、客户端密钥等信息。例如:
代码语言:txt
复制
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文档

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券