Skip to content
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

Handle Default Authentication using events #16884

Merged
merged 7 commits into from
Oct 24, 2024
Merged

Conversation

MikeAlhayek
Copy link
Member

@MikeAlhayek MikeAlhayek commented Oct 14, 2024

By utilizing middleware instead of controllers for performance optimization, we can keep the login code streamlined and free from excessive external authentication logic.

@Piedone
Copy link
Member

Piedone commented Oct 15, 2024

How does using a middleware instead of a controller optimize performance?

@kevinchalet
Copy link
Member

I agree with @Piedone, there's likely no gain at all to expect from a performance perspective. On the other hand, moving that to a middleware introduces new risks like responses collision (you're not checking whether the response has already been sent or not so you could potentially end up in a situation where your custom middleware will end up calling SignOutAsync() on an HTTP response whose headers have already been returned, which isn't going to work with hosts that use streamed responses).

If performance was your main motivation for that, I'd say it's not worth the risk 😃

@MikeAlhayek
Copy link
Member Author

@Piedone

How does using a middleware instead of a controller optimize performance?

Quicker response time since it's done earlier on "before routing to a controller, and much less resource to create during the login request

@kevinchalet main goal isn't performance here since this is only handled by one action. Main goal is to clean up the code so that the external authentication logic isn't coupled with the code in the Users feature. Also, to reduce the amount of code we used for the default login logic.

@kevinchalet
Copy link
Member

Quicker response time since it's done earlier on "before routing to a controller, and much less resource to create during the login request

Did you measure it? 😄

It's worth noting that middleware aren't really free. And unlike the existing approach, the price will now be paid for basically all requests (e.g you'll have to pay for the async state machine whether the request path matches or not the /login path). I really doubt you'll win anything substantial by converting the existing controller to a middleware.

@kevinchalet main goal isn't performance here since this is only handled by one action. Main goal is to clean up the code so that the external authentication logic isn't coupled with the code in the Users feature. Also, to reduce the amount of code we used for the default login logic.

In this case, why not an event? It's the good old way of doing things in Orchard 😃

@MikeAlhayek
Copy link
Member Author

Did you measure it?

No. Again, the idea behind this PR isn't optimization is more of decoupling the code. But, optimization and reducing allocations would be nice too.

In this case, why not an event? It's the good old way of doing things in Orchard

I am open to ideas. How would we use handlers in this case challenge the request from an action?

@MikeAlhayek
Copy link
Member Author

@kevinchalet I am now using event to handle this which simplifies the code and we won't need a middleware.

@MikeAlhayek MikeAlhayek changed the title Handle Default Authentication using Middleware Handle Default Authentication using events Oct 17, 2024
@MikeAlhayek
Copy link
Member Author

@Piedone anything else to add here?

Copy link
Member

@kevinchalet kevinchalet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@Piedone
Copy link
Member

Piedone commented Oct 18, 2024

I see there's no middleware anymore, so good enough for me :). Can't comment otherwise.

@sebastienros
Copy link
Member

We had a discussion about base classes during triage and decided (we forced Mike) to remove the base class. We think that we should accept base classes in these conditions:

  • We can provide a single implementation of a base class if it adds some value (no empty base class)
  • We provide 2 or more implementations to show there is a behavior to choose from
  • We don't implementation default interface methods, unless to prevent a breaking change (adding a new method to the interface)
  • Base classes are documented with the reason when to use it (ideally any consumable implementation of an interface)

@MikeAlhayek MikeAlhayek merged commit bd93e29 into main Oct 24, 2024
12 checks passed
@MikeAlhayek MikeAlhayek deleted the ma/improve-external-auth branch October 24, 2024 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants