Yancy::Plugin::Roles - Role-based access controls (RBAC)
version 1.085
plugin Yancy => ...; plugin Auth => ...; plugin Roles => { schema => 'roles', userid_field => 'username', };
Note: This module is EXPERIMENTAL and its API may change before Yancy v2.000 is released.
EXPERIMENTAL
This plugin provides user authorization based on roles. Roles are created by using the "require_role" method. User accounts are provided by Yancy::Plugin::Auth (or a subclass). Accounts are mapped to roles in the database.
This plugin has the following configuration options.
The name of the Yancy schema that holds role memberships. Required.
The name of the field in the schema which is the user's identifier. This field should be named the same in both the user schema and the roles schema.
The name of the field in the schema which holds the role. Defaults to role.
role
This plugin has the following helpers.
Return true if the current user has the given role.
get '/admin' => sub { my $c = shift; return $c->reply->not_found unless $c->yancy->auth->has_role( 'admin' ); };
Validate there is a logged-in user and that the user belongs to the given role(s). Returns a callback that can be used in under.
under
my $require_admin = $app->yancy->auth->require_role( 'admin' ); my $admin_routes = $app->routes->under( '/admin', $require_admin );
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.