【问题标题】:Owin hosted web app using Token authentication使用令牌身份验证的 Owin 托管 Web 应用程序
【发布时间】:2015-06-04 16:23:57
【问题描述】:

我正在尝试使用令牌身份验证创建一个 owin Web 应用程序,我的启动没有任何特殊设置,如

中的示例

https://github.com/NancyFx/Nancy/wiki/Token-Authentication

public class Bootstrapper : DefaultNancyBootstrapper
{
    protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
    {
        TokenAuthentication.Enable(pipelines, new TokenAuthenticationConfiguration(container.Resolve<ITokenizer>()));
    }
}

我的很简单

public void Configuration(IAppBuilder app)
{
    app.UseNancy();
}

我的模块定义如下

public HomeModule(ITokenizer tokenizer)
{

    Post["/login"] = _ =>
    {
        DefaultUserIdentityResolver resolver = new DefaultUserIdentityResolver();
        //var userName = (string)this.Request.Form.Username;
        //var password = (string)this.Request.Form.Password;

        var claims = new List<string> { "admin", "poweruser" };

        var userIdentity = resolver.GetUser("ross", claims, Context);
        if (userIdentity == null)
        {
            return HttpStatusCode.Unauthorized;
        }

        var token = tokenizer.Tokenize(userIdentity, Context);

        return new
        {
            Token = token,
        };
    };
}

目前我知道的不多,但是当我进行标记时,我得到了 Nancy.ErrorHandling.RouteExecutionEarlyExitException 类型的异常,它在消息或堆栈跟踪中确实没有任何内容来指示问题。

我目前在 .NET 4.5.1 的 casini 中通过 http 托管

任何指针将不胜感激

更新:

消息是:

Exception of type 'Nancy.ErrorHandling.RouteExecutionEarlyExitException' was thrown.

Stack trace is:
   at Nancy.Authentication.Token.Tokenizer.Tokenize(IUserIdentity userIdentity, NancyContext context)
   at Samaritan.Hosting.HttpServices.HomeModule.<>c__DisplayClass11.<.ctor>b__7(Object _) in c:\src\DukeSoftware\Samaritan\Main\Samaritan.Hosting.HttpServices\HomeModule.cs:line 39
   at CallSite.Target(Closure , CallSite , Func`2 , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at Nancy.Routing.Route.<>c__DisplayClass4.<Wrap>b__3(Object parameters, CancellationToken context)

我尝试像这样设置 startup.cs

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseNancy();
    }
}

public class Bootstrapper : DefaultNancyBootstrapper
{
    protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
    {
        TokenAuthentication.Enable(pipelines, new TokenAuthenticationConfiguration(container.Resolve<ITokenizer>()));
    }
}

但我遇到了以下异常

{"Located multiple bootstrappers:\r\n - Samaritan.Hosting.HttpServices.BootStarapper\r\n - Samaritan.Hosting.HttpServices.Bootstrapper\r\n\r\nEither remove unused bootstrapper types or specify which type to use."}

所以我删除了引导程序并离开了 Startup。当您声明构造函数 public HomeModule(ITokenizer tokenizer) 时,似乎将实例化的标记器传递到模块中 所以我不认为tokenizer的创建是个问题

【问题讨论】:

  • 你能发布异常消息和堆栈跟踪吗?
  • 另外:您的应用程序中有引导程序吗?

标签: owin nancy http-token-authentication


【解决方案1】:

你找到解决办法了吗?

我遇到了同样的异常。这是因为我在同一个目录中有 2 个 EXE 文件,它们是 'DefaultNancyBootstrapper' 类的子级。

我必须使用旧的 Nancy v1.0。所以似乎没有其他办法,只能在一个地方使用“DefaultNancyBootstrapper”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    • 1970-01-01
    • 2014-02-20
    • 2013-11-25
    • 2013-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多