-
Notifications
You must be signed in to change notification settings - Fork 463
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
Switched to events model to DI of event type #495
Conversation
Hi Dru, thank you for the contribution! Let me understand the rationale a bit better, I'll come back with questions. |
Why Can you post your old and new code side-by-side. I'm all for a better usage experience, so want to see understand how does the proposed change improve it. |
It's of type |
.AddJwt(JwtAuthenticationDefaults.AuthenticationScheme, options =>
{
options.OnSuccessfulTicket = (logger, ticket) =>
{
// ARGH - I can get at the DbContext
};
});
// later
builder.Services.AddTransient<DoTheWorkHereAsAWorkAround>(); |
Sounds like the right strategy then. Thank you again! Please add some tests and other paperwork (version bump, changelog) |
@abatishchev ok, so the next step that I'd like to discuss is moving the events to a "context" approach - but I'm also happy to make that a different PR. The idea is to copy what we see in other authentication handlers like you see here: The big things that I think this adds which is nice.
I hesitate to take this move in this PR because it would break the API. I can get what I need with just what we have. But to bring it even closer to the GoogleAuthenticationHandler this would be the next step I'd like to do - but happy to do it in another PR. Also, when we are done, I can squash all of these commits into one clean commit. Is that preferred? |
I like the approach (especially given it's a pattern) and don't mind a breaking change (ideally of course we just mark old things as |
Ok, it'll be a bit before I get to it but I'll put the context objects in. I'll chew on how to best make the old stuff still work. It should totally be doable. Just need to think on it. :) |
We also can check in the current PR, just without releasing the package Either way, sounds good to me! |
Or what I usually did earlier, bump the major version but suffic it with let's say |
@abatishchev ok, with this latest push we have context classes with more data available. YAY! The old methods are still supported, although right now its either/or. You can't do both. I'd be game to do a |
Ok, did a review of |
@abatishchev ok, updated change log - saw you got the version numbers. Feeling pretty good right now. Any other items you want me to square away? |
7fd55b8
to
e8d2741
Compare
@drusellers can you please check why the build failed? |
@abatishchev do we have a way to cut a beta nuget that I can put into my projects and get some "burn in time" with it? |
Yes, sure. Every check (build) procudes a NuGet package you can download and consume (from the disk). Once merged, I'll publish it to NuGet.org too. But would be great if you could give it a local try first! |
2a98b58
to
0dbeafc
Compare
@drusellers I rebased your branch on the latest main after I ran into a few merge conflicts. Can you please check if I missed anything? |
All tests passed, I'm ready to check it in |
@abatishchev sorry for the delay, was heads down on some other projects. I'll look to grab the latest and report back. TY! |
Description
while working on some JWT code, I'd like to set the HttpContext.Items with a hydrated user. This follows a similar pattern seen in the Cookie and various other authentication systems.
We introduce a new
JwtAuthenticationEvents
type, that mirrors the exact same events. Following the Cookie Authentication I moved all of theOnXxxx
to theEvents
object. I added [Obsolete] tags to the oldOnXxx
methods with instructions about what to use instead.If we want we can also extend the
OAuthEvents
if that suits us as well.I need to figure out how to best test this, but this is a pattern I've used to build my own Basic auth and MagicLink auth. Before I go any further I wanted to check in with the team on this direction.
The goal is to be able to inject my DbContext into the handler, so that I can populate the HttpContext.Items
Checklist