【发布时间】:2011-05-06 21:06:44
【问题描述】:
我正在测试使用 OpenRasta 作为 ASP.NET MVC 的可行替代方案的可行性。 但是,我遇到了关于身份验证的绊脚石。
让我明确一点,“Open Digest Authentication”目前不是一个选项。
我读到 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();
}
}
}
所以,我需要知道下一步我需要采取哪些步骤,因此我要求一个真正的工作模型,而不仅仅是理论答案,因为我 2 天前刚刚偶然发现了这个框架并且可能不知道所有OpenRasta 框架,RESTful 术语,你可能会扔给我 :)
一旦我掌握了身份验证,我就会很好地了解如何继续评估是否将现有的 asp.net 原型门户移植到 OpenRasta。
提前谢谢...
【问题讨论】:
标签: rest basic-authentication openrasta