OpenRasta-Scott Littlewoods基本身份验证工作示例 [英] OpenRasta - Scott Littlewoods Basic Authentication working example

查看:89
本文介绍了OpenRasta-Scott Littlewoods基本身份验证工作示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试使用OpenRasta作为ASP.NET MVC的可行替代方案的可行性. 但是,我遇到了有关身份验证的绊脚石.

I'm testing out the feasibility of using OpenRasta as a viable alternative to ASP.NET MVC. However, I've run into a stumbling block regarding authentication.

让我清楚一点,目前还不能选择开放式摘要式身份验证" .

我已经读到Scott Littlewood为OpenRasta创建了一个基本的身份验证分支,并且我已经从git下载源代码并成功构建了它.

I've read that Scott Littlewood created a basic authentication fork for OpenRasta and I've downloaded the source from git and successfully built it.

我现在正在尝试使身份验证正常工作,因此,如果有人拥有真正的工作模型,我将不胜感激.到目前为止,这是我所做的:

I'm now trying to get the authentication working, so if someone has a real working model, I would be very grateful. Here's what I've done so far:

//Authentication.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using OpenRasta;
using OpenRasta.Configuration;
using OpenRasta.Authentication;
using OpenRasta.Authentication.Basic;
using OpenRasta.Configuration.Fluent;
using OpenRasta.DI;

namespace myOpenRastaTest.Extensions
{
    public static class ExtensionsToIUses
    {
        public static void BasicAuthentication<TBasicAuthenticator>(this IUses uses) where TBasicAuthenticator : class, IBasicAuthenticator
        {
            uses.CustomDependency<IAuthenticationScheme, BasicAuthenticationScheme>(DependencyLifetime.Transient);

            uses.CustomDependency<IBasicAuthenticator, TBasicAuthenticator>(DependencyLifetime.Transient);
        }
    }

    public class CustomBasicAuthenticator : IBasicAuthenticator
    {
        public string Realm { get { return "stackoverflow-realm"; } }

        public CustomBasicAuthenticator()
        {            
        }

        public AuthenticationResult Authenticate(BasicAuthRequestHeader header)
        {
            /* use the information in the header to check credentials against your service/db */
            if (true)
            {
                return new AuthenticationResult.Success(header.Username);
            }

            return new AuthenticationResult.Failed();
        }
    }
}

现在要对其进行测试,我刚刚在HomeHandler.cs中创建了一个CustomBasicAuthenticator实例:

Now to test it I just created an instance of CustomBasicAuthenticator in my HomeHandler.cs:

//HomeHandler.cs
using System;
using myOpenRastaTest.Resources;

namespace myOpenRastaTest.Handlers
{
    public class HomeHandler
    {
        public object Get()
        {
            var custAuth = new myOpenRastaTest.Extensions.CustomBasicAuthenticator();

            return new HomeResource();
        }
    }
}

因此,我需要知道下一步需要采取的步骤,因此我之所以要求一个真正的工作模型,而不仅仅是理论上的答案,是因为两天前我偶然发现了该框架,并且可能不知道全部OpenRasta框架,RESTful术语,您可能会反驳我:)

So, I need to know what steps i need to take next, hence the reason for me asking for a real working model and not just theory answers since I've just stumbled upon the framework 2 days ago and might not know all the OpenRasta framework,RESTful lingo that you might throw back at me :)

一旦掌握了身份验证,就可以很好地指示如何继续评估是否将现有的asp.net原型门户移植到OpenRasta.

Once I get a grasp of authentication, I'll have a good indication as to how to proceed with my evaluation of whether to port an existing asp.net prototype portal to OpenRasta or not.

预先感谢...

推荐答案

我有一个使用新的OpenRasta身份验证过程的示例应用程序,该过程目前仅支持BASIC身份验证.

I have a sample application using the new OpenRasta authentication process that ONLY supports BASIC authentication at the moment.

使用不同的身份验证方案应该很简单,但是我最近没有时间这样做.

Plugging in different authentication schemes should be quite straight forward but I haven't had the time recently to do this.

请参阅以下github讨论以供将来参考: https://github.com/scottlittlewood/openrasta-stable/commit/25ee8bfbf610cea17626a9e7dfede565f662d7bb#comments

See this github discussion for future reference: https://github.com/scottlittlewood/openrasta-stable/commit/25ee8bfbf610cea17626a9e7dfede565f662d7bb#comments

有关工作示例,请在此处签出代码: https://github.com/scottlittlewood/OpenRastaAuthSample

For a working example checkout the code here: https://github.com/scottlittlewood/OpenRastaAuthSample

希望这会有所帮助

这篇关于OpenRasta-Scott Littlewoods基本身份验证工作示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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