使用IdentityServer3拥有中间件.ASP中的AccessTokenValidation.净5 ?返回空对象异

本文关键字:返回 对象 AccessTokenValidation 拥有 IdentityServer3 中间件 ASP 中的 使用 | 更新日期: 2023-09-27 18:07:31

我试图获得IdentityServer3。accessstokenvalidation在ASP中工作。. NET 5 Web应用程序,但下面的代码抛出一个空异常我错过了什么?

项目。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

使用IdentityServer3拥有中间件.ASP中的AccessTokenValidation.净5 ?返回空对象异

我也有这个NullPointerException。问题是方法app.GetLoggerFactory();(从IAppBuilder)返回null。在我的例子中,这个方法在我调用

后返回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,但这是另一个问题。