Yancy::Plugin::Auth::Role::RequireUser - Add authorization based on user attributes
version 1.072
use Mojolicious::Lite; plugin Yancy => ...; # Require any user my $require_user = app->yancy->auth->require_user; my $user = app->routes->under( '/user', $require_user ); # Require a user with the `is_admin` field set to true my $require_admin = app->yancy->auth->require_user( { is_admin => 1 } ); my $admin = app->routes->under( '/admin', $require_admin );
Note: This module is EXPERIMENTAL and its API may change before Yancy v2.000 is released.
EXPERIMENTAL
This plugin adds a simple authorization method to your site. All default Yancy auth plugins use this role to provide the yancy.auth.require_user helper.
yancy.auth.require_user
my $subref = $c->yancy->auth->require_user( \%match );
Build a callback to validate there is a logged-in user, and optionally that the current user has certain fields set. \%match is optional and is a SQL::Abstract where clause matched with "match" in Yancy::Util.
\%match
# Ensure the user is logged-in my $user_cb = $app->yancy->auth->require_user; my $user_only = $app->routes->under( $user_cb ); # Ensure the user's "is_admin" field is set to 1 my $admin_cb = $app->yancy->auth->require_user( { is_admin => 1 } ); my $admin_only = $app->routes->under( $admin_cb );
Yancy::Plugin::Auth
Doug Bell <preaction@cpan.org>
This software is copyright (c) 2021 by Doug Bell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Yancy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Yancy
CPAN shell
perl -MCPAN -e shell install Yancy
For more information on module installation, please visit the detailed CPAN module installation guide.