トークン認証を使用して owin Web アプリを作成しようとしています。私のスタートアップには、例のような特別な設定はありません。
https://github.com/NancyFx/Nancy/wiki/トークン認証
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 のカジノで 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."}
そのため、ブートラッパーを削除して、スタートアップを終了しました。コンストラクタ public を宣言すると、インスタンス化されたトークナイザがモジュールに渡されるように見えるHomeModule(ITokenizer tokenizer)
ので、トークナイザの作成が問題になるとは思いませんでした