Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

AuthenticationHandler.InitializeAsync chokes when HandleAuthenticateAsync returns null #760

Closed
@kevinchalet

Description

@kevinchalet

When working on the events model of the aspnet-contrib introspection middleware, @MonkeyJamboree discovered that returning null from HandleAuthenticateAsync caused a NullReferenceException:

    AspNet.Security.OAuth.Introspection.Tests.OAuthIntrospectionMiddlewareTests.
SkippedResponseAfterAccessTokenReceivedEventCausesInvalidAuthentication [FAIL]
      System.NullReferenceException : Object reference not set to an instance of
 an object.
      Stack Trace:
           at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.<Initi
alizeAsync>d__48.MoveNext()
        --- End of stack trace from previous location where exception was thrown
 ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Tas
k task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDeb
uggerNotification(Task task)
           at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<In
voke>d__18.MoveNext()
        --- End of stack trace from previous location where exception was thrown
 ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Tas
k task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDeb
uggerNotification(Task task)
           at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMidd
leware.<Invoke>d__3.MoveNext()
        --- End of stack trace from previous location where exception was thrown
 ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Tas
k task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDeb
uggerNotification(Task task)
           at Microsoft.AspNetCore.TestHost.ClientHandler.<>c__DisplayClass3_0.<
<SendAsync>b__0>d.MoveNext()
        --- End of stack trace from previous location where exception was thrown
 ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Tas
k task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDeb
uggerNotification(Task task)
           at Microsoft.AspNetCore.TestHost.ClientHandler.<SendAsync>d__3.MoveNe
xt()
        --- End of stack trace from previous location where exception was thrown
 ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Tas
k task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDeb
uggerNotification(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
           at AspNet.Security.OAuth.Introspection.Tests.OAuthIntrospectionMiddle
wareTests.<SkippedResponseAfterAccessTokenReceivedEventCausesInvalidAuthenticati
on>d__12.MoveNext()
        --- End of stack trace from previous location where exception was thrown
 ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Tas
k task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDeb
uggerNotification(Task task)
        --- End of stack trace from previous location where exception was thrown
 ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Tas
k task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDeb
uggerNotification(Task task)
        --- End of stack trace from previous location where exception was thrown
 ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Tas
k task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDeb
uggerNotification(Task task)

This exception is likely caused by this null check: https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNetCore.Authentication/AuthenticationHandler.cs#L105.

Not a big deal, but something we may want to fix for RC2 or RTM.

/cc @HaoK @Tratcher

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions