简体   繁体   English

OWIN 自定义认证服务

[英]OWIN custom Authentication Service

I need to create a Single Page Application that support authentication.我需要创建一个支持身份验证的单页应用程序。 Our business already have a authentication service.我们的企业已经有了身份验证服务。

I just don't know where to start.我只是不知道从哪里开始。

Scenario:设想:

The user tries to access a protected method in a controller:用户尝试访问控制器中的受保护方法:

[Authorize]
public class MeController : Controller

Since he is not logged in, he's redirected to the login page:由于他没有登录,他被重定向到登录页面:

 [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                //Call business authentication service
                if (GetClient().OpenSession(model.username, model.password))
                    // Set Cookie? Implement some Owin interfaces?
            }   
            // If we got this far, something failed, redisplay form
            return View(model);
        }

As you can see, this is under the opensession that I need to do something to create the cookie or...??如您所见,这是在 opensession 下,我需要做一些事情来创建 cookie 或...??

Also, since we would like to use Facebook and Google OWIN authentication, I thought I could implement my own OWIN classes?另外,由于我们想使用 Facebook 和 Google OWIN 身份验证,我想我可以实现自己的 OWIN 类吗?

In summary, the idea here is not to use SQL SERVER or any other database to store the users information.总之,这里的想法不是使用 SQL SERVER 或任何其他数据库来存储用户信息。 Just call our own service?只是调用我们自己的服务?

What to do?该怎么办?

Here's the link that you should get started with using OWIN for Authentication https://msdn.microsoft.com/en-us/magazine/dn745860.aspx这是您应该开始使用 OWIN 进行身份验证的链接https://msdn.microsoft.com/en-us/magazine/dn745860.aspx

Before you get started get familiar with hwo OWIN works.在开始之前,先熟悉一下 OWIN 的工作原理。 Also beware that OWIN doesn't support cookie-less login but on the other hand it support Claims which is more than just a role provider.还要注意,OWIN 不支持无 cookie 登录,但另一方面,它支持 Claims,这不仅仅是一个角色提供者。

There are pre-developed OAuth implementation of OWIN for Facebook, Google at Katana codeplex page.Katana codeplex页面上有针对 Facebook、Google 的 OWIN 的预开发 OAuth 实现。 Also If you want to integrate more providers here 'sa github project that has developed almost all OAuth providers.另外如果你想集成更多的提供者, 这里是一个开发了几乎所有 OAuth 提供者的 github 项目。

Good luck!!祝你好运!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM