jhthorsen / mojolicious-plugin-openapi

OpenAPI / Swagger plugin for Mojolicious
54 stars 42 forks source link

Another take on allowing different status codes #186

Closed Skeeve closed 4 years ago

Skeeve commented 4 years ago

This one stashes a default 401 - unless there already is a status in the stash A 500 will always be stashed.

With this approach the security callback can stash its own value (like 403) when user is authenticated but not authorized

In my case I do it like this:

if ($assume_client ne $apiuser and $account->{level} < 9999) {
    $c->stash( status => 403 );
    return 'permission denied' ;
};

Advantage over my other approach:

Skeeve commented 4 years ago
jhthorsen commented 4 years ago

Looks great! Thanks for ending up with a very small diff and also adding the test 👍