3

ASP.NETMVCの実行可能な代替手段としてOpenRastaを使用する可能性をテストしています。しかし、私は認証に関してつまずきに遭遇しました。

はっきりさせておきますが、現時点では「オープンダイジェスト認証」はオプションではありません。

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に移植するかどうかの評価をどのように進めるかについての良い指標が得られます。

前もって感謝します...

4

2 に答える 2

2

現在、BASIC 認証のみをサポートする新しい OpenRasta 認証プロセスを使用するサンプル アプリケーションがあります。

さまざまな認証スキームをプラグインするのは非常に簡単なはずですが、最近これを行う時間がありませんでした。

今後の参考のために、この github の議論を参照してください。

実際の例については、こちらのコードをチェックしてください: https://github.com/scottlittlewood/OpenRastaAuthSample

お役に立てれば

于 2010-11-09T10:59:16.057 に答える
1

認証を設定したら、リソース ハンドラーの 1 つに承認を与えることでトリガーする必要があります。これは、たとえば、RequiresAuthentication 属性を追加することで実行できます。

その属性のコードを見て、カスタム承認を自分で実装する方法を確認できます。

于 2010-11-08T21:22:33.230 に答える