【发布时间】:2019-12-25 10:24:22
【问题描述】:
我在 ASP.Net 核心中有一个应用程序,分为 3 个项目(API、数据、服务)。 API 包含将调用服务项目中的方法的控制器(我将在其中处理数据)。
我现在使用的是 ASP 提供的认证系统,所以我在启动方法中添加了这些行。
services.AddIdentity<IdentityUser,IdentityRole>().AddEntityFrameworkStores<RHPDbContext>();
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.SaveToken = true;
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
{
ValidateIssuer = true,
ValidateAudience = true,
ValidAudience = "RHP User",
ValidIssuer = "MYIssuer",
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("MyRHPSuperKey"))
};
});
由于我正在制作 API,我将需要基于令牌的身份验证
并且还在startup的configure方法中添加了这一行
app.UseAuthentication();
我现在的问题是如何在我的服务项目中访问userManager,以便我可以添加用户,或获取用户,将角色属性分配给用户......等等
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-core asp.net-web-api