dotnet / dotnet/aspnetcore

ResourceInvoker no longer used with single authentication Scheme, causing issues with ActionContext

Open
#48,893 1 comment 1 reaction 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Since .net 7 there is a [breaking change in the default authentication scheme](https://learn.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/7.0/default-authentication-scheme#new-behavior) that causes weird behavior when trying to use the `IActionContextAccessor`. If you only have 1 authentication scheme registered, it is automatically set as default schema, and the `ResouceInvoker` is not used. The `ResourceInvoker` is responsible for setting the `ActionContext` on the `IActionContextAccessor` dependency

Now we need to add a dummy schema to ensure the requests uses the `ResourceInvoker`

### Expected Behavior

Both with one or more authentication schemes registered, the `ResourceInvoker` should always be used

### Steps To Reproduce

A reproduction scenario can be found [here](https://github.com/PaulVrugt/actioncontextexample)

When you set a breakpoint in `Schema1.cs` on line 27, start the project and call the weatherforecast api, you can see that the `controllerContext` variable is null. Once you uncomment line 13 of `program.cs` and run the application again, the `controllerContext` variable is filled, and you can also see in the stacktrace (see `anything else`) that the `ResourceInvoker` is being used

### Exceptions (if any)

_No response_

### .NET Version

7.0.302

### Anything else?

this is the stacktrace when `controllerContext` is unavailable:
![wrongstack](https://github.com/dotnet/aspnetcore/assets/7567114/5ea6d3b0-1992-4456-b221-cbe700c24ed8)

this is the callstack when `controllerContext` IS available (notice the `ResourceInvoker`, which is responsible for setting the `ActionContext` on the `IActionContextAccessor`):
![workingstack](https://github.com/dotnet/aspnetcore/assets/7567114/8d5bf98f-5f38-4600-a67e-5d528b4e0941)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.