客户端指能够从你的 identityserver 请求令牌的应用程序。html
细节可能有所不一样,可是客户端一般有如下设置web
在运行时,客户端经过
IClientStore
的实现来检索。 这容许从配置文件或数据库的任意数据源加载它们。 对于本文档,咱们将使用客户端存储的内存存储版本。 您能够经过AddInMemoryClients
扩展方法在ConfigureServices
中配置内存存储。数据库
在这种状况下,没有交互式用户 - 服务(也称为客户端)想要与API(aka范围)进行通讯:api
public class Clients { public static IEnumerable<Client> Get() { return new List<Client> { new Client { ClientId = "service.client", ClientSecrets = { new Secret("secret".Sha256()) }, AllowedGrantTypes = GrantTypes.ClientCredentials, AllowedScopes = { "api1", "api2.read_only" } } }; } }
这个客户端使用implicit flow来从JavaScript请求身份和访问令牌:安全
var jsClient = new Client { ClientId = "js", ClientName = "JavaScript Client", ClientUri = "http://identityserver.io", AllowedGrantTypes = GrantTypes.Implicit, AllowAccessTokensViaBrowser = true, RedirectUris = { "http://localhost:7017/index.html" }, PostLogoutRedirectUris = { "http://localhost:7017/index.html" }, AllowedCorsOrigins = { "http://localhost:7017" }, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, IdentityServerConstants.StandardScopes.Email, "api1", "api2.read_only" } };
交互式服务器端(或本地桌面/移动)应用程序使用混合流程(hybrid flow)。 这个流程为您提供了最好的安全性,由于访问令牌仅经过反向通道传输(并容许您访问刷新令牌):服务器
var mvcClient = new Client { ClientId = "mvc", ClientName = "MVC Client", ClientUri = "http://identityserver.io", AllowedGrantTypes = GrantTypes.Hybrid, AllowOfflineAccess = true, ClientSecrets = { new Secret("secret".Sha256()) }, RedirectUris = { "http://localhost:21402/signin-oidc" }, PostLogoutRedirectUris = { "http://localhost:21402/" }, FrontChannelLogoutUri = "http://localhost:21402/signout-oidc", AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, IdentityServerConstants.StandardScopes.Email, "api1", "api2.read_only" }, };