ASP.Net-Core 中的自定义身份验证 [英] Custom Authentication in ASP.Net-Core

查看:32
本文介绍了ASP.Net-Core 中的自定义身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要与现有用户数据库集成的网络应用程序.我仍然想使用 [Authorize] 属性,但我不想使用 Identity 框架.如果我确实想使用 Identity 框架,我会在 startup.cs 文件中添加如下内容:

services.AddIdentity(options =>{options.Password.RequireNonLetterOrDigit = false;}).AddEntityFrameworkStores().AddDefaultTokenProviders();

我假设我必须在那里添加其他东西,然后创建某种实现特定接口的类?有人可以指出我正确的方向吗?我现在正在使用 asp.net 5 的 RC1.

解决方案

可以通过多种方式在 ASP.NET Core 中创建自定义身份验证.如果您想构建现有组件(但不想使用身份),请查看 docs.asp.net 上文档的安全"类别.https://docs.asp.net/en/latest/security/index.html

一些您可能会觉得有用的文章:

使用没有 ASP.NET 身份的 Cookie 中间件>

基于策略的自定义授权

当然,如果失败或文档不够清楚,源代码位于https://github.com/dotnet/aspnetcore/tree/master/src/Security 其中包括一些示例.

I am working on a web app that needs to integrate with an existing user database. I would still like to use the [Authorize] attributes, but I don't want to use the Identity framework. If I did want to use the Identity framework I would add something like this in the startup.cs file:

services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
    options.Password.RequireNonLetterOrDigit = false;
}).AddEntityFrameworkStores<ApplicationDbContext>()
  .AddDefaultTokenProviders();

I'm assuming I have to add something else there, and then create some kind of class that implements a specific interface? Can somebody point me in the right direction? I'm using RC1 of of asp.net 5 right now.

解决方案

Creating custom authentication in ASP.NET Core can be done in a variety of ways. If you want to build off existing components (but don't want to use identity), checkout the "Security" category of docs on docs.asp.net. https://docs.asp.net/en/latest/security/index.html

Some articles you might find helpful:

Using Cookie Middleware without ASP.NET Identity

Custom Policy-Based Authorization

And of course, if that fails or docs aren't clear enough, the source code is at https://github.com/dotnet/aspnetcore/tree/master/src/Security which includes some samples.

这篇关于ASP.Net-Core 中的自定义身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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