问题描述
好像没有很多关于如何做的授权与新的MVC的版本信息。由于ASP 5正处于RC 1人能猜出你现在就可以开始尝试了解其如何去上班......
It seems like there is not a lot of information about how to do authorization with the new MVC version. Since ASP 5 now is in RC 1 one could guess that you now can start trying to understand how its going to work...
我想要做的是一个包含用户名和角色的身份验证令牌的只是一个简单的例子。
像一个链接http://bitoftech.net/2015/03/11/asp-net-identity-2-1-roles-based-authorization-authentication-asp-net-web-api/将有助于大大,但似乎很难找到
What I want to do is just a simple example of an auth token that contains the user's name and roles.A link like http://bitoftech.net/2015/03/11/asp-net-identity-2-1-roles-based-authorization-authentication-asp-net-web-api/ would help greatly but seems hard to find
推荐答案
您可以尝试为。您需要RC2使用它,但它是很容易设置:
You can try OpenIddict for that. You need RC2 to use it, but it's quite easy to set up:
public void ConfigureServices(IServiceCollection services) {
services.AddMvc();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders()
.AddOpenIddict(); // Add the OpenIddict services after registering the Identity services.
}
public void Configure(IApplicationBuilder app) {
app.UseOpenIddict();
}
肖恩·沃尔什贴在自己的博客中详细解说:。
这篇关于在ASP MVC 6令牌身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!