From Code to Community: Sponsoring The Perl and Raku Conference 2025 Learn more

NAME

Amon2::Plugin::Web::Auth - auth with SNS

SYNOPSIS

package MyApp::Web;
# simple usage
# more configurable...
__PACKAGE__->load_plugin(
'Web::Auth' => {
module => 'Facebook',
on_finished => sub {
my ($c, $token, $user) = @_;
...
}
}
);

DESCRIPTION

Amon2::Plugin::Web::Auth is authentication engine for Amon2.

THIS MODULE IS EXPERIMENTAL STATE. SOME API CHANGES WITHOUT NOTICE.

CONFIGURATION IN CODE

module

This is a module name for authentication plugins. You can write 'Amon2::Auth::Site::Facebook' as 'Facebook' in this part. If you want to use your own authentication module, you can write it as '+My::Own::Auth::Module' like DBIx::Class.

__PACKAGE__->load_plugin(
'Web::Auth' => {
module => 'Twitter',
...
}
);
# or
__PACKAGE__->load_plugin(
'Web::Auth' => {
module => '+My::Own::Auth::Module',
...
}
);
on_finished

This is a callback when authentication flow was finished. You MUST return a response object in this callback function. You MAY return the response of $c->redirect().

__PACKAGE__->load_plugin('Web::Auth', {
module => 'Github',
on_finished => sub {
my ($c, $token, $user) = @_;
my $gihtub_id = $user->{id} || die;
my $github_name = $user->{name} || die;
$c->session->set('name' => $github_name);
$c->session->set('site' => 'github');
return $c->redirect('/');
}
});

The arguments of this callback function is a auth module specific.

user_info

In auth module that uses OAuth2, is not required to fetch user information, just get a access_token. If you don't need a user information, you can set false value on this attribute.

This attribute is true by default on most modules for your laziness.

on_error

Auth module calls this callback function when error occurred.

Arguments are following format.

my ($c, $err) = @_;

The default value is following.

sub {
my ($c, $err) = @_;
die "Authentication error in $module: $err";
}

AUTHOR

Tokuhiro Matsuno <tokuhirom AAJKLFJEF GMAIL COM>

SEE ALSO

LICENSE

Copyright (C) Tokuhiro Matsuno

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.