Skip to content

How to hook authorization into ja_resource? #32

@begedin

Description

@begedin

In our project, we would like to use ja_resource but we're having issues with authorising users. In a lot of cases, the user being authorised to perform an action depends on the changeset they are trying to persist. (For example, an admin can demote another admin, but they should not be allowed to promote them to a higher role). That would mean, that, at some point, we would have to hook into the changeset generated by handle_create/update, call authorisation on that changeset and then either allow ja_resource to continue or halt everything due to lack of proper rights.

The way the whole create process works right now, it doesn't really allow us to put a plug between the loading of resource/creation of changeset and performing of action.

Ideally, we would have something like the option to split up the default ja_resource plug into two of them, so that

plug Authenticate when action in [:create, :update, :delete]
plug JaResource

could become

plug MyApp.Authenticate when action in [:create, :update, :delete]
plug JaResource.load
plug MyApp.Authorize
plug JaResource.perform

Looking at #30, we could split it even further, potentially having something like

plug MyApp.Authenticate when action in [:create, :update, :delete]
plug JaResource.load
plug MyApp.Authorize
plug JaResource.perform
plug MyApp.Track
plug JaResource.render

Any thoughts on that? Our team would definitely find it useful, but it might be overkill.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions