Skip to content

Add ability to return failed authorization requests #74

Open
@Cardosaum

Description

Is your feature request related to a problem? Please describe.

I see in the documentation that is stated as one of the main reasons one would not consider using LetMe the inability to provide more detailed information on why an authorization request failed:

You need to provide details on why an authorization request fails. Checks in LetMe currently return only a boolean value, meaning users receive a generic error without knowing which exact check failed. (Source)

I'm sure this is intentional, but I don't fully comprehend why the library present this design choice; Wouldn't the ability to return a {:error, reason} tuple instead of simply false be a sensible choice in order to provide more flexibility for end users?

My issue arises from the fact that I can't easily point why an authorization request failed - If I have a policy like:

object :object1 do
    action :create do
        allow [:requirement1, :requirement2, :requirement3, ...]
    end
end

It would be useful to have transparency on which exact check failed, but currently I'm only able to get {:error, :unauthorized}.

Describe the solution you'd like

It would be great if I could specify the reason for a failed test in the check itself.
For example something like:

defmodule MyApp.Policy.Checks do
  def requirement1(%User{id: id}, %{user_id: id}), do: true
  def requirement1(_subject, _object), do: {:error, :unsatisfied_requirement1}

  def requirement2(%Something{}, _), do: true
  def requirement2(subject, object), do: {:error, :unsatisfied_requirement2}
end

Describe alternatives you've considered

From what I could see, Bodyguard does have the ability to specify a custom error/reason - Which is great, but after seen how nicely LetMe handles things, I would really prefer sticking with it if possible.

Additional context

I know that the design choice for this behavior was deliberate, but I can't understand exactly why...

@woylie , would you be able to clarify the reasons for such an option?


Also, I'd like to say that the work done in LetMe is great, and I'm thankful for all your efforts and providing the Elixir ecosystem a great library! 🙇‍♂️

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions