benvanstaveren / Mojolicious-Plugin-Authentication

A plugin to make authentication a bit easier
http://search.cpan.org/dist/Mojolicious-Plugin-Authentication/
Other
20 stars 17 forks source link

Authenticated and Signed Conditions. #5

Closed SailingYYC closed 12 years ago

SailingYYC commented 12 years ago

Hi Ben, Kudos on an excellent plugin!

I have a circumstance where depending on a client's setup they may want users authenticated for certain routes while other clients don't. I immediately thought of of using (authenticated => $loginreq), but it always failed, regardless of value for $loginreq.

I peaked at the code and the present logic will always fail if $required <> true. Below is a diff that permits this behaviour, which based on the naming conventions I'm guessing was your intent. Can you advise if this was your intent or if there is a known downfall? I would love to see this incorporated so I don't have to fork for such a simple modification.

Most appreciated, Colin.

70c70
<         return ($required && $c->is_user_authenticated) ? 1 : 0;

---
>         return (!$required || $c->is_user_authenticated) ? 1 : 0;
75c75
<         return ($required && $c->signature_exists) ? 1 : 0;

---
>         return (!$required || $c->signature_exists) ? 1 : 0;
SailingYYC commented 12 years ago

Thank you, most appreciated.

Although I've spent the last hour trying to find a way to pass a variable value (set in a before_dispatch) to authenticated without success. It would appear the routing condition is a closure. I'm still new to Mojolicious so am trying to figure things out...