如果Api资源与IdentityServer4在同一个项目里时如何访问
1、添加客户端时在AllowedScopes里添加IdentityServerApi
代码示例如下:
Client oneResult = new Client { ClientId = client.ClientId, ClientName = client.ClientName, AllowedGrantTypes = GrantTypes.ClientCredentials, ClientSecrets = { new Secret("123456784".Sha256()) }, AllowedScopes = { client.Scope, "IdentityServerApi" }, AuthorizationCodeLifetime = 36000, IdentityTokenLifetime = 36000, AccessTokenLifetime = 36000, DeviceCodeLifetime = 36000, UserSsoLifetime = 36000, AllowOfflineAccess = true };
2、传值时,加上IdentityServerApi的Scope
appsetting里配置的示例如下:
"ClientId": "CommonAPI", "ClientSecret": "12345678", "Scope": "CommonAPI IdentityServerApi"
多个Scope之间用空格进行分隔