| Exactly. Since mix phx.gen.auth handles the authN side, it’s really just authZ that will be idiosyncratic to your application logic. In every authorization system I’ve written in a Phoenix app (which 8 now), I’ve taken this approach above. Make a pipeline of rules that take a conn or socket and authorize or not based on what’s in the assigns. Better yet, at the very top of the pipleline, wrap the conn or socket with an auth struct that holds metadata like authorization status and any redirection to be done. Unwrap that struct into the conn or the socket at the end of the pipeline, where the status is resolved. This way, every request can be default unauthorized and you can apply complex, composable rules for granting permission to take various actions on resources. |
(I am a bit bitter after implementing authentication with Firebase and authorization in a Phoenix app? Maybe ahah).