我正在測試使用OpenRasta作爲ASP.NET MVC的可行替代方案的可行性。但是,我遇到了關於認證的絆腳石。OpenRasta - Scott Littlewoods基本身份驗證工作示例
讓我清楚,在這一點上,「開放摘要式身份驗證」不是一個選項。
我讀過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。
在此先感謝...
斯科特,工作的例子就是一個很好的例子。非常直接和高效。這正是我所要求的。 非常感謝。 - PS。任何計劃爲ASP.NET實施「表單身份驗證」?我已經在期待關於不安全的Forms Auth可以如何的回覆:) – ph2004 2010-11-09 16:47:06
如果您正在尋找Cookie認證,那麼可以看看牙買加https://www.ohloh.net/p/jamaica。 – Psiren 2010-11-10 17:31:45