rest - OpenRasta - Scott Littlewoods 基本身份验证工作示例

标签 rest basic-authentication openrasta

我正在测试使用 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();
        }
    }
}

所以,我需要知道下一步需要采取什么步骤,因此我要求一个真正的工作模型而不仅仅是理论答案的原因,因为我 2 天前刚刚偶然发现该框架并且可能不知道所有OpenRasta 框架,RESTful 行话,你可能会向我吐槽 :)

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

提前致谢...

最佳答案

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

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

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

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

希望对你有帮助

关于rest - OpenRasta - Scott Littlewoods 基本身份验证工作示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4127764/

相关文章:

java - jersey RESTful api 在使用 FormDataMultipart 时回复 415 不受支持的媒体类型

java - 在 dropwizard REST API 中返回两个具有相同值的字段

node.js - Botpress 网络聊天身份验证

REST 服务基本身份验证 session 超时

php - 单页应用程序的访问控制列表

REST - 处理子资源访问

c# - Asp.Net:没有适合 AuthenticationMiddleware 的构造函数

.net - 什么对 REST API 更好? WCF Web API(预览版 4)或 OpenRasta 或其他什么?

c# - 自定义身份验证 OpenRasta

rest - 是否可以在没有 IIS 的情况下安装和使用 OpenRasta?如果是这样,怎么办?