Skip to content

OpenIdConnectUserAccessTokenHandler throws NRE while no httpContext #324

@e5tamp

Description

@e5tamp

Affected component

Duende.AccessTokenManagement.OpenIdConnect

Version

4.1.1

Describe the bug

Problem with using OpenIdConnectUserAccessTokenHandler

if HttpContextAccessor.HttpContext?.User is null your HttpContextUserAccessor.GetCurrentUserAsync() returns new ClaimsPrincipal() with NO identity. After that in UserAccessTokenManagementService.cs in UserAccessAccessTokenManager.GetAccessTokenAsync there is an exception:

System.NullReferenceException
Object reference not set to an instance of an object.
at Duende.AccessTokenManagement.OpenIdConnect.UserAccessAccessTokenManagementService.GetAccessTokenAsync()

This exception occurs in 37 line because of null forgiving if (!user.Identity!.IsAuthenticated). This code throws exception and makes it impossible to use other httpClientHandlers. Remove null-forgiving or return new ClaimsPrincipal(new ClaimsIdentity()) in HttpContextUserAccessor.GetCurrentUserAsync()

Steps to reproduce

Register OpenIdConnectUserAccessTokenHandler. Run some request to httpClient with no httpContext.

Expected behavior

No Exception. Return TokenResult.Failure("No active user");

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/foss/atmIssues related to Access Token Management

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions