Identityserver4 ASP.NET 3.1中Identity Server 4中的ApiResources配置在哪里?
在ASP.NET Core 2.2教程中介绍了scaffold Identity Server 4内存项目模板之后,Identityserver4 ASP.NET 3.1中Identity Server 4中的ApiResources配置在哪里?,identityserver4,Identityserver4,在ASP.NET Core 2.2教程中介绍了scaffold Identity Server 4内存项目模板之后,ApiResources配置位于appsettings.json "ApiResources": [ { "Name": "movie.api", "DisplayName": "Movie API Services", "S
ApiResources
配置位于appsettings.json
"ApiResources": [
{
"Name": "movie.api",
"DisplayName": "Movie API Services",
"Scopes": [
{
"Name": "movie.api",
"DisplayName": "Movie API Services"
}
]
}
],
但是,在ASP.NET Core 3.1中,appsettings.json
不再存在,而是被Config.cs
取代。但是,我在那里找不到ApiResources
。如何在Config.cs
中创建ApiResources
这是我现有的Config.cs
公共静态类配置
{
公共静态IEnumerable IdentityResources=>
新标识资源[]
{
新标识资源.OpenId(),
新标识资源.Profile(),
})
publicstaticIEnumerableApiscopes=>
新安培镜[]
{
新ApiScope(“scope1”),
新ApiScope(“scope2”),
};
公共静态IEnumerable客户端=>
新客户[]
{
//m2m客户端凭据流客户端
新客户
{
ClientId=“m2m.client”,
ClientName=“客户端凭据客户端”,
AllowedGrantTypes=GrantTypes.ClientCredentials,
ClientSecrets={newsecret(“511536EF-F270-4058-80CA-1C89C192F69A”.Sha256())},
AllowedScopes={“scope1”}
},
//使用码流+pkce的交互式客户端
新客户
{
ClientId=“交互式”,
ClientSecrets={newsecret(“49C1A7E1-0C79-4A89-A3D6-A37998FB86B0”.Sha256())},
AllowedGrantTypes=GrantTypes.Code,
重定向URI={”https://localhost:44300/signin-oidc“},
FrontChannelLogoutUri=”https://localhost:44300/signout-oidc“,
PostLogoutRedirectUris={”https://localhost:44300/signout-回调oidc“},
AllowOfflineAccess=true,
AllowedScopes={“openid”、“profile”、“scope2”}
},
//客户端-配置标识服务
//步骤2:注册客户端
新客户
{
ClientId=“movie.web”,//与startup.cs中定义的内容匹配
//ClientSecrets={newsecret(“49C1A7E1-0C79-4A89-A3D6-A37998FB86B0”.Sha256())},
AllowedGrantTypes=GrantTypes.Implicit,
重定向URI={”http://localhost:5000/signin-oidc“},
//FrontChannelLogoutUri=”https://localhost:44300/signout-oidc“,
//PostLogoutRedirectUris={”https://localhost:44300/signout-回调oidc“},
//AllowOfflineAccess=true,
AllowedScopes={“openid”,“profile”},
AllowAccessTokensViaBrowser=true
},
};
}
通过一种最简单的方式,您可以将其添加到Config.cs
中,如下所示:
public static IEnumerable<ApiScope> ApiScopes =>
new ApiScope[]
{
new ApiScope("movie.api")
};
public static IEnumerable<ApiResource> ApiResources =>
new ApiResource[]
{
new ApiResource("movie.api", "The Movie API")
{
Scopes = { "movie.api" }
}
};
var builder = services.AddIdentityServer(options =>
.AddInMemoryIdentityResources(Config.IdentityResources)
.AddInMemoryApiScopes(Config.ApiScopes)
.AddInMemoryApiResources(Config.ApiResources)
.AddInMemoryClients(Config.Clients)
.AddTestUsers(TestUsers.Users);
但是在IdentityServer4的版本4中,作用域有自己的定义,并且可以选择由资源引用。这意味着,如果你不需要,你不必拥有ApiResource
阅读更多
var builder = services.AddIdentityServer(options =>
.AddInMemoryIdentityResources(Config.IdentityResources)
.AddInMemoryApiScopes(Config.ApiScopes)
.AddInMemoryApiResources(Config.ApiResources)
.AddInMemoryClients(Config.Clients)
.AddTestUsers(TestUsers.Users);