【发布时间】:2020-04-20 08:25:24
【问题描述】:
我有 2 个项目 API 和 Auth Server 使用 asp.net core 3.1 。在 API 项目中,我使用身份服务器 4 令牌验证来验证令牌。我也在 API 项目中使用身份。
下面是api项目中代币验证的代码
var authAuthority = "https://localhost:5000"; // Configuration["BlazorBoilerplate:IS4ApplicationUrl"].TrimEnd('/');
var authBuilder = services.AddAuthentication(options =>
{
options.DefaultScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;
})
.AddIdentityServerAuthentication(options =>
{
options.Authority = authAuthority;
options.SupportedTokens = SupportedTokens.Jwt;
options.RequireHttpsMetadata = false;
options.ApiName = "weatherapi";
});
令牌验证后,用户声明显示在 httpContext.User.Identity 对象中。请参考屏幕截图。
如果我在 ConfigureServices 类的下面代码中添加了身份服务。
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentity<User, Role>()
.AddRoles<Role>()
.AddEntityFrameworkStores<CBSContext>()
.AddDefaultTokenProviders();
}
添加上述asp.net身份服务后,AuthorizationHandlerContext显示为空。身份服务和身份服务器令牌验证之间是否有任何关系。
- 身份验证服务器中的用户身份验证 --- 完美运行
-
我需要在 API 项目中使用身份的用户/角色管理器。 我只是想将 services.AddDefaultIdentity 更改为 i 身份服务器 jwt 验证怎么做?
请推荐..
【问题讨论】:
标签: asp.net-core asp.net-identity ef-core-3.0