Asp.net core 我是否可以只使用IdentityServer4中的数据库,而不是在Config.cs中写入所有客户端
我一直在搜索IdentityServer4如何使用DB。我已经阅读了:并查看了使用DB存储的QuickStart4。我找不到的是如何在多客户端场景中使用它,在这种场景中,我们只想将客户端详细信息添加到DB,而不必将客户端添加到Identity Server中的config.cs,如下所示:Asp.net core 我是否可以只使用IdentityServer4中的数据库,而不是在Config.cs中写入所有客户端,asp.net-core,identityserver4,Asp.net Core,Identityserver4,我一直在搜索IdentityServer4如何使用DB。我已经阅读了:并查看了使用DB存储的QuickStart4。我找不到的是如何在多客户端场景中使用它,在这种场景中,我们只想将客户端详细信息添加到DB,而不必将客户端添加到Identity Server中的config.cs,如下所示: public static class Config { public static IEnumerable<IdentityResource> IdentityResources =&g
public static class Config
{
public static IEnumerable<IdentityResource> IdentityResources =>
new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
};
public static IEnumerable<ApiScope> ApiScopes =>
new List<ApiScope>
{
new ApiScope("api1", "My API")
};
public static IEnumerable<Client> Clients =>
new List<Client>
{
// machine to machine client
new Client
{
ClientId = "client",
ClientSecrets = { new Secret("secret".Sha256()) },
AllowedGrantTypes = GrantTypes.ClientCredentials,
// scopes that client has access to
AllowedScopes = { "api1" }
},
// interactive ASP.NET Core MVC client
new Client
{
ClientId = "mvc",
ClientSecrets = { new Secret("secret".Sha256()) },
AllowedGrantTypes = GrantTypes.Code,
// where to redirect to after login
RedirectUris = { "https://localhost:5002/signin-oidc" },
// where to redirect to after logout
PostLogoutRedirectUris = { "https://localhost:5002/signout-callback-oidc" },
AllowedScopes = new List<string>
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"api1"
}
}
};
}
公共静态类配置
{
公共静态IEnumerable IdentityResources=>
新名单
{
新标识资源.OpenId(),
新标识资源.Profile(),
};
公共静态IEnumerable ApiScopes=>
新名单
{
新的ApiScope(“api1”、“我的API”)
};
公共静态IEnumerable客户端=>
新名单
{
//机器对机器客户端
新客户
{
ClientId=“客户端”,
ClientSecrets={newsecret(“Secret.Sha256())},
AllowedGrantTypes=GrantTypes.ClientCredentials,
//客户端有权访问的作用域
AllowedScopes={“api1”}
},
//交互式ASP.NET核心MVC客户端
新客户
{
ClientId=“mvc”,
ClientSecrets={newsecret(“Secret.Sha256())},
AllowedGrantTypes=GrantTypes.Code,
//登录后重定向到哪里
重定向URI={”https://localhost:5002/signin-oidc“},
//注销后重定向到何处
PostLogoutRedirectUris={”https://localhost:5002/signout-回调oidc“},
AllowedScopes=新列表
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
“api1”
}
}
};
}
}查看本页和本页
基本上,您需要做的是:
或者,您可以实现自己的IClientStore实现。请查看@Qudus,我已经看到了,但我的场景是一个不涉及用户的机器对机器身份验证。有几个API客户端将使用自己的证书进行身份验证。