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
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