I have a smallish Yesod application (using the scaffold). I’d like to add basic HTTP authentication to all requests. Here’s what I tried so far:
- I’ve read the docs on Yesod authentication, but there’s unfortunately no backend supporting this.
isAuthorizedwould be great, but I can’t see a way to read the headers there.- A WAI middleware would be elegant, but I can’t find any documentation describing how to use one with a full Yesod application. It’s also pretty clear that writing one is not completely trivial.
Was this already done? How should I approach this?
I’ve come up with a non-ideal solution: I prepend an action to all my handler functions. Maybe it’ll be useful for someone, maybe someone can improve upon this. Here’s the code:
And using it:
I’ll be more than happy to move the “accepted” checkmark if a better solution is posted.