在ASP MVC 6令牌身份验证 [英] Token auth in asp mvc 6

查看:124
本文介绍了在ASP MVC 6令牌身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像没有很多关于如何做的授权与新的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...

我想要做的是一个包含用户名和角色的身份验证令牌的只是一个简单的例子。
像一个链接<一个href=\"http://bitoftech.net/2015/03/11/asp-net-identity-2-1-roles-based-authorization-authentication-asp-net-web-api/\" rel=\"nofollow\">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

推荐答案

您可以尝试 OpenIddict 为。您需要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();
}

肖恩·沃尔​​什贴在自己的博客中详细解说:的http:/ /capesean.co.za/blog/asp-net-5-jwt-tokens/

这篇关于在ASP MVC 6令牌身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆