1

I am trying to get the IdentityServer3.AccessTokenValidation to work in a ASP.NET 5 Web application but the code below throws a null exception am I missing something?

project.json - dependencies (partial)

"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" }
        });

Extension method

    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;
            });
        });
    }

The following line keeps on throwing a null object exception but unable to determine what is missing

builder.UseIdentityServerBearerTokenAuthentication(options);

Stacktrace

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)

I am using the identity server below

https://github.com/IdentityServer/IdentityServer3.Samples/tree/master/source/AspNet5Host

1 Answer 1

2

I also had this NullPointerException. The issue is that the method app.GetLoggerFactory(); (from the IAppBuilder) returns null. In my case this method returns null after I call

app.Map("/admin", adminApp =>
        {
            var factory = new IdentityManagerServiceFactory();
            factory.ConfigureSimpleIdentityManagerService();

            adminApp.UseIdentityManager(new IdentityManagerOptions()
            {
                Factory = factory
            });
        });

So placing the the method builder.UseIdentityServerBearerTokenAuthentication(options); before the app.Map solves the NullPointer issue. But now I have the problem that it seems that it is not possible to host the WebApi and the IdentityServer in the same project, but that's another issue..

2
  • Have you managed getting this working within ASP.NET 5? the extension method defined within the nugget package IdentityServer3.AccessTokenValidation has been designed for OWIN only so I used the Microsoft.AspNet.WebApi.Owin package which contains the UseOwin extension method which can be used to bridge between OWIN and ASP.NET 5 Aug 16, 2015 at 17:41
  • 1
    Yes it is working. So the WebApi and the IdentityServer can run in the same application you have to use ValidationMode = ValidationMode.ValidationEndpoint. Otherwise it is trying to discover the data during the startup and at this point of time the IdentityServer is not running.
    – huer12
    Aug 17, 2015 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.