-
Notifications
You must be signed in to change notification settings - Fork 69
Set current principal if available #78
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
Conversation
|
@davidfowl @Tratcher Is there a reason we shouldn't do this? The backing of the |
|
I think this is fine from a compatibility perspective but not from a "do by default in ASP.NET Core" perspective:
|
|
Yea, thread.currentprincipal is to be avoided as much as possible, it messes up badly with async as David says, it never worked well with impersonation (not that we're encouraging impersonation either), and 1st and 3rd party libraries made so many bad assumptions we pushed the AAD folks away from it. I'm not sure we would even want this from a compat POV given its tendency to go wrong. |
|
That makes sense to not include it in the product itself and I get the desire to move away from it. However, since a lot of code currently does use it, what about it being something we make available with these adapters to opt into? This could either be per route (via metadata) or a global option. I've created a PR that enables a request to be (logically) a single thread by limiting concurrency with #82. Would that make any of this better? We could only set Thread.CurrentPrincipal when single threaded behavior is enabled. Additionally, what if we were to wrap the IPrincipal set to the current thread with a custom implementation to emit warnings if anyone were to access members from it? |
|
Single threaded? Woohoo welcome back STA :) Yea, that'd work. I think an opt-in, with a dire warning is enough. |
|
@blowdart @davidfowl Thanks for the comments I've updated this PR to do the following:
I did also try overwriting the ClaimsPrincipal.Selector function to log warnings if it is accessed and to use HttpContextAccessor directly, but ended up removing it as the other warnings will probably be sufficient. This is all opt-in and hopefully will help users understand it's not best practice but enable them to more easily migrate old code. |
|
I like these changes a lot. I appreciate your work here. |
|
We shouldn’t have a wanting that logs per request, let’s get rid of it. Put something in the doc comments. |
No description provided.