Skip to content

Make it possible to turn off OpenID Connect configuration retrieval, or enable removal of an added authentication handler #61168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
ChrisKlug opened this issue Mar 26, 2025 · 10 comments
Milestone

Comments

@ChrisKlug
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

During integration testing with the WebApplicationFactory, I tend replace the existing authentication method (OIDC) with basic auth to simplify testing. However, in the current model, it seems more or less impossible to remove an authentication handler once it has been added. This is a problem with the OIDC handler, as it makes a request to retrieve the OIDC configuration on startup, which causes problems during testing.

Describe the solution you'd like

It would be great to be able to remove an authentication handler after it has been added, e.g. in the ConfigureTestServices method. Alternatively, it could be solved by being able to configure the OIDC handler to not get the configuration automatically.

Additional context

Right now, my solution is to set a specific environment name in the tests, and have code that checks the environment name before adding the OIDC handler. However, this feels less than optimal, as I don't want to have test specific code in my production application.

@ChrisKlug ChrisKlug closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2025
@ChrisKlug ChrisKlug reopened this Apr 2, 2025
@ChrisKlug
Copy link
Contributor Author

The solution that was suggested to me at some point was to use IAuthenticationSchemeProvider.RemoveScheme. However, this would require me to build the application first to get hold of the ´IAuthenticationSchemeProvider´. I would like to do it during set-up in ´ConfigureTestServices()´.

@danroth27 danroth27 changed the title Make it possible to turn of OpenID Connect configuration retrieval, or enable removal of an added authentication handler Make it possible to turn off OpenID Connect configuration retrieval, or enable removal of an added authentication handler Apr 2, 2025
@MackinnonBuck
Copy link
Member

@ChrisKlug, what's wrong with building the service provider first, then modifying the schemes after? Have you taken a look at AuthenticationOptions.SchemeMap?

@MackinnonBuck MackinnonBuck added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Apr 2, 2025
@ChrisKlug
Copy link
Contributor Author

Is the call to the OIDC configuration endpoint not done during creation? Or is that called at a later point? I thought it was done during creation, in which case it is too late to remove it after creation...

@dotnet-policy-service dotnet-policy-service bot added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Apr 2, 2025
@ChrisKlug
Copy link
Contributor Author

Also, it would feel better to do it before creation to me. As I really don't want it in there. But that is a subjective thing I guess

@MackinnonBuck
Copy link
Member

Is the call to the OIDC configuration endpoint not done during creation? Or is that called at a later point?

It happens on the first request.

@ChrisKlug, is there a reason you could add something to your app's configuration (e.g., create some kind of testing configuration), and then set up the app's auth differently depending on the current configuration?

@MackinnonBuck MackinnonBuck added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Apr 7, 2025
@ChrisKlug
Copy link
Contributor Author

If it's on first request, I should be able to remove the handler in my test after the creation of the app using the IAuthenticationSchemeProvider.RemoveScheme. I thought I tested that, but I'll have to try again.

I currently have a conditional that only adds the OIDC handler if the environment isn't my integration testing. But I'd rather not have code that is test specific deployed to test...

@dotnet-policy-service dotnet-policy-service bot added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Apr 7, 2025
@halter73
Copy link
Member

To progress further on this issue, I think we'll need example code that does not work that you would like to have work.

@halter73 halter73 added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Apr 14, 2025
@ChrisKlug
Copy link
Contributor Author

ChrisKlug commented Apr 21, 2025

I created a little sample of what I am talking about. It's available here: https://github.com/ChrisKlug/asp-net-core-auth-example

It is quite easily fixed using IAuthenticationSchemeProvider after the creation of the app. I am just feeling like it isn't where I would expect to find it. I would expect to be able to do it in the ConfigureTestServices method. Which I guess I why I have never found the IAuthenticationSchemeProvider way, as I wasn't looking to remove it after it had already been created...

I get that it might not be a high priority issue, but I still think it would make it easier to discover if it was available in ConfigureTestServices. In the same way that integration testing ASP.NET Core would be a lot easier to understand if the NuGet package didn't include the MVC part...

@dotnet-policy-service dotnet-policy-service bot added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Status: No Recent Activity labels Apr 21, 2025
@MackinnonBuck MackinnonBuck added this to the Backlog milestone Apr 21, 2025
@MackinnonBuck MackinnonBuck removed the Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. label Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants