-
Notifications
You must be signed in to change notification settings - Fork 598
Reading Request.Body on AuthenticationHandler causes model null on MVC #1638
Comments
You need to buffer the body, e.g. to a memory stream if it's small, seek back to the start, and then re-assign Request.Body. |
Is the body tiny? How big can it get? |
@Tratcher i've tried some things, but MVC always get a null model. @davidfowl We'll, it's a library, so it can be any size. Currently i'm the only using, so i'm sure the body wont be so big. |
You’ll probably destroy the performance if you buffer a large body in memory. Just FYI. |
That's what i was thinking. |
Show us how you tried to buffer. As far as perf goes, there's not much you can do. That validation algorithm itself is fundamentally inefficient. Time to switch auth schemes? |
Sorry for the late.
Probably i was messing up with @Tratcher the algorithm is inefficient, i know. It's just a playground. Anyway, what is the other performant way to work with Body without using MemoryStream? |
You're not going to be able to do much better when your HMAC code requires hashing the entire body before the application gets access to it. If the body gets really large you could buffer it to disk. See EnableRewind: |
I have a similar use-case to @grandchamp, where I need to hash the entire body to verify a webhook call
|
We periodically close 'discussion' issues that have not been updated in a long period of time. We apologize if this causes any inconvenience. We ask that if you are still encountering an issue, please log a new issue with updated information and we will investigate. |
Hi.
What i'm trying to do is to read the
Request.Body
on a customAuthenticationHandler
but when i do this, the Model passed to MVC is null (probably because you can't read theRequest.Body
twice).The code is https://github.com/grandchamp/AuthAPI/blob/master/AuthAPI.Middlewares.Mvc/AuthAPIAuthenticationHandler.cs#L58.
What can i do here?
The text was updated successfully, but these errors were encountered: