客戶端指能夠從你的 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" }, };