3

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

让我明确一点,此时“开放式摘要身份验证”不是一个选项

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

我现在正试图让身份验证工作,所以如果有人有一个真正的工作模型,我将非常感激。这是我到目前为止所做的:

//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 实例:

//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 的术语,你可能会反击我 :)

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

提前致谢...

4

2 回答 2

2

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

插入不同的身份验证方案应该非常简单,但我最近没有时间这样做。

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

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

希望这可以帮助

于 2010-11-09T10:59:16.057 回答
1

一旦您进行了身份验证,您需要通过对您的资源处理程序之一进行授权来触发它,例如,您可以通过在其上添加 RequiresAuthentication 属性来实现。

您可以查看该属性的代码以了解如何自己实现自定义授权。

于 2010-11-08T21:22:33.230 回答