在 ASP.NET 5 中使用 IdentityServer3.AccessTokenValidation 的 owin 中间件? returns空对象异常
owin middlware with IdentityServer3.AccessTokenValidation in ASP.NET 5? returns null object exception
我正在尝试让 IdentityServer3.AccessTokenValidation 在 ASP.NET 5 Web 应用程序中工作,但下面的代码抛出一个 null 异常,我是否遗漏了什么?
project.json - 依赖关系(部分)
"IdentityServer3.AccessTokenValidation": "2.0.0-build00019",
"Microsoft.AspNet.WebApi.Owin": "5.2.3",
"Microsoft.Owin.Host.SystemWeb": "3.0.1",
"Microsoft.AspNet.Authentication.OAuthBearer": "1.0.0-beta6",
"Microsoft.Owin.Security.OAuth": "3.0.0",
"Microsoft.AspNet.Owin": "1.0.0-beta6",
"Microsoft.AspNet.Authorization": "1.0.0-beta6",
"Microsoft.IdentityModel.Protocol.Extensions": "1.0.0",
"Newtonsoft.Json": "6.0.6"
Startup.cs
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "https://localhost:44300/",
RequiredScopes = new[] { "api1" }
});
扩展方法
public static void UseIdentityServerBearerTokenAuthentication(this IApplicationBuilder app, IdentityServerBearerTokenAuthenticationOptions options)
{
app.UseOwin(addToPipeline =>
{
addToPipeline(next =>
{
var builder = new Microsoft.Owin.Builder.AppBuilder();
builder.UseIdentityServerBearerTokenAuthentication(options);
var appFunc = builder.Build(typeof(Func<IDictionary<string, object>, Task>)) as Func<IDictionary<string, object>, Task>;
return appFunc;
});
});
}
下面这行一直在抛空对象异常,但无法确定缺少什么
builder.UseIdentityServerBearerTokenAuthentication(options);
堆栈跟踪
At IdentityServer3.AccessTokenValidation.DiscoveryDocumentIssuerSecurityTokenProvider..ctor(String discoveryEndpoint, IdentityServerBearerTokenAuthenticationOptions options, ILoggerFactory loggerFactory) in c:\projects\thinktecture-identityserver-v3- accesstokenvalidati\source\AccessTokenValidation\Plumbing\DiscoveryDocumentIssuerSecurityTokenProvider.cs:line 43
at Owin.IdentityServerBearerTokenValidationAppBuilderExtensions.ConfigureLocalValidation(IdentityServerBearerTokenAuthenticationOptions options, ILoggerFactory loggerFactory) in c:\projects\thinktecture-identityserver-v3-accesstokenvalidati\source\AccessTokenValidation\IdentityServerBearerTokenValidationAppBuilderExtensions.cs:line 100
at Owin.IdentityServerBearerTokenValidationAppBuilderExtensions.UseIdentityServerBearerTokenAuthentication(IAppBuilder app, IdentityServerBearerTokenAuthenticationOptions options) in c:\projects\thinktecture-identityserver-v3-accesstokenvalidati\source\AccessTokenValidation\IdentityServerBearerTokenValidationAppBuilderExtensions.cs:line 50
at Portal.IdentityServerAccessTokenValidationAppBuilderExtensions.<>c__DisplayClass0_0.<UseIdentityServerBearerTokenAuthentication>b__1(Func`2 next) in C:\code\Sense.Care\src\Portal\Configuration\IdentityServerAccessTokenValidationAppBuilderExtensions.cs:line 23
at Microsoft.AspNet.Builder.OwinExtensions.<>c__DisplayClass0_1.<UseOwin>b__1(RequestDelegate next1)
at Microsoft.AspNet.Builder.Internal.ApplicationBuilder.Build()
at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication()
at Microsoft.AspNet.Hosting.Internal.HostingEngine.Start()
at Microsoft.AspNet.Loader.IIS.RuntimeHttpApplication.ApplicationStart(IHttpApplication application)
at Microsoft.AspNet.Loader.IIS.HttpApplicationBase.InvokeApplicationStart(IHttpApplication application)
我正在使用下面的身份服务器
https://github.com/IdentityServer/IdentityServer3.Samples/tree/master/source/AspNet5Host
我也有这个 NullPointerException。问题是方法 app.GetLoggerFactory()
; (来自 IAppBuilder)returns 空。
在我的例子中,这个方法 returns null 在我调用
之后
app.Map("/admin", adminApp =>
{
var factory = new IdentityManagerServiceFactory();
factory.ConfigureSimpleIdentityManagerService();
adminApp.UseIdentityManager(new IdentityManagerOptions()
{
Factory = factory
});
});
因此将方法 builder.UseIdentityServerBearerTokenAuthentication(options);
放在 app.Map 之前解决了 NullPointer 问题。
但现在我遇到的问题是,似乎无法在同一个项目中托管 WebApi 和 IdentityServer,但这是另一个问题..
我正在尝试让 IdentityServer3.AccessTokenValidation 在 ASP.NET 5 Web 应用程序中工作,但下面的代码抛出一个 null 异常,我是否遗漏了什么?
project.json - 依赖关系(部分)
"IdentityServer3.AccessTokenValidation": "2.0.0-build00019",
"Microsoft.AspNet.WebApi.Owin": "5.2.3",
"Microsoft.Owin.Host.SystemWeb": "3.0.1",
"Microsoft.AspNet.Authentication.OAuthBearer": "1.0.0-beta6",
"Microsoft.Owin.Security.OAuth": "3.0.0",
"Microsoft.AspNet.Owin": "1.0.0-beta6",
"Microsoft.AspNet.Authorization": "1.0.0-beta6",
"Microsoft.IdentityModel.Protocol.Extensions": "1.0.0",
"Newtonsoft.Json": "6.0.6"
Startup.cs
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "https://localhost:44300/",
RequiredScopes = new[] { "api1" }
});
扩展方法
public static void UseIdentityServerBearerTokenAuthentication(this IApplicationBuilder app, IdentityServerBearerTokenAuthenticationOptions options)
{
app.UseOwin(addToPipeline =>
{
addToPipeline(next =>
{
var builder = new Microsoft.Owin.Builder.AppBuilder();
builder.UseIdentityServerBearerTokenAuthentication(options);
var appFunc = builder.Build(typeof(Func<IDictionary<string, object>, Task>)) as Func<IDictionary<string, object>, Task>;
return appFunc;
});
});
}
下面这行一直在抛空对象异常,但无法确定缺少什么
builder.UseIdentityServerBearerTokenAuthentication(options);
堆栈跟踪
At IdentityServer3.AccessTokenValidation.DiscoveryDocumentIssuerSecurityTokenProvider..ctor(String discoveryEndpoint, IdentityServerBearerTokenAuthenticationOptions options, ILoggerFactory loggerFactory) in c:\projects\thinktecture-identityserver-v3- accesstokenvalidati\source\AccessTokenValidation\Plumbing\DiscoveryDocumentIssuerSecurityTokenProvider.cs:line 43
at Owin.IdentityServerBearerTokenValidationAppBuilderExtensions.ConfigureLocalValidation(IdentityServerBearerTokenAuthenticationOptions options, ILoggerFactory loggerFactory) in c:\projects\thinktecture-identityserver-v3-accesstokenvalidati\source\AccessTokenValidation\IdentityServerBearerTokenValidationAppBuilderExtensions.cs:line 100
at Owin.IdentityServerBearerTokenValidationAppBuilderExtensions.UseIdentityServerBearerTokenAuthentication(IAppBuilder app, IdentityServerBearerTokenAuthenticationOptions options) in c:\projects\thinktecture-identityserver-v3-accesstokenvalidati\source\AccessTokenValidation\IdentityServerBearerTokenValidationAppBuilderExtensions.cs:line 50
at Portal.IdentityServerAccessTokenValidationAppBuilderExtensions.<>c__DisplayClass0_0.<UseIdentityServerBearerTokenAuthentication>b__1(Func`2 next) in C:\code\Sense.Care\src\Portal\Configuration\IdentityServerAccessTokenValidationAppBuilderExtensions.cs:line 23
at Microsoft.AspNet.Builder.OwinExtensions.<>c__DisplayClass0_1.<UseOwin>b__1(RequestDelegate next1)
at Microsoft.AspNet.Builder.Internal.ApplicationBuilder.Build()
at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication()
at Microsoft.AspNet.Hosting.Internal.HostingEngine.Start()
at Microsoft.AspNet.Loader.IIS.RuntimeHttpApplication.ApplicationStart(IHttpApplication application)
at Microsoft.AspNet.Loader.IIS.HttpApplicationBase.InvokeApplicationStart(IHttpApplication application)
我正在使用下面的身份服务器
https://github.com/IdentityServer/IdentityServer3.Samples/tree/master/source/AspNet5Host
我也有这个 NullPointerException。问题是方法 app.GetLoggerFactory()
; (来自 IAppBuilder)returns 空。
在我的例子中,这个方法 returns null 在我调用
app.Map("/admin", adminApp =>
{
var factory = new IdentityManagerServiceFactory();
factory.ConfigureSimpleIdentityManagerService();
adminApp.UseIdentityManager(new IdentityManagerOptions()
{
Factory = factory
});
});
因此将方法 builder.UseIdentityServerBearerTokenAuthentication(options);
放在 app.Map 之前解决了 NullPointer 问题。
但现在我遇到的问题是,似乎无法在同一个项目中托管 WebApi 和 IdentityServer,但这是另一个问题..