2010-11-08 64 views
3

我正在測試使用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。

在此先感謝...

回答

2

我有一個示例應用程序使用新的OpenRasta身份驗證過程,目前只支持BASIC身份驗證。

插入不同的認證方案應該是非常直接的,但我最近沒有時間去做這件事。

見以供將來參考此github上討論:https://github.com/scottlittlewood/openrasta-stable/commit/25ee8bfbf610cea17626a9e7dfede565f662d7bb#comments

對於工作的例子在這裏檢出代碼:https://github.com/scottlittlewood/OpenRastaAuthSample

希望這有助於

+0

斯科特,工作的例子就是一個很好的例子。非常直接和高效。這正是我所要求的。 非常感謝。 - PS。任何計劃爲ASP.NET實施「表單身份驗證」?我已經在期待關於不安全的Forms Auth可以如何的回覆:) – ph2004 2010-11-09 16:47:06

+0

如果您正在尋找Cookie認證,那麼可以看看牙買加https://www.ohloh.net/p/jamaica。 – Psiren 2010-11-10 17:31:45

1

一旦你有了到位的認證,你需要它在您的資源處理程序,您可以通過它添加RequiresAuthentication屬性爲做一個有授權被觸發例。

您可以查看該屬性的代碼,以瞭解如何自己實現自定義授權。