Din*_*ino 4 c# access-token .net-core identityserver4 asp.net-core-webapi
我有一个托管IdentityServer4的项目,并且尝试在同一项目中托管一个Web API,该API接受访问令牌。
我的问题是,单个项目是否可能包含IdentityServer和使用同一IdentityServer的Web API?
编辑:必须使用Authorize属性保护API
我有一个身份服务器4项目,在同一项目中,有一个用于CIUD客户端的API。(称之为开发者控制台API)。
然后,我有一个附带项目,即一个asp .net核心项目,其中包含开发人员控制台的实际剃刀页面,它可以访问Identity Server项目中的API。
我这样做的原因是,只有一个项目应该更新数据库。因此,为了更新身份服务器拥有的数据库,决定用于访问它的API也应该在同一项目中。
是的,您可以在Identity Server 4项目中使用Web api。
配置服务
services.AddAuthentication(IdentityServerConstants.DefaultCookieAuthenticationScheme)
.AddIdentityServerAuthentication(options =>
{
// base-address of your identityserver
options.Authority = settingsSetup.Settings.Authority;
// name of the API resource
options.ApiName = "testapi";
options.RequireHttpsMetadata = false;
});
Run Code Online (Sandbox Code Playgroud)
配置
我认为这两个都需要。
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
app.UseAuthentication();
app.UseIdentityServer();
Run Code Online (Sandbox Code Playgroud)
终点
由于使用访问令牌作为承载令牌发送请求,因此每个API调用的授权都必须包含authencationScheme。我还没有弄清楚为什么,但是没有这个,它是行不通的。
[HttpGet("Client/List")]
[Authorize(AuthenticationSchemes = "Bearer")]
public ActionResult ClientList()
{
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1465 次 |
| 最近记录: |