Amon2::Plugin::Web::Auth - auth with SNS
package MyApp::Web; # simple usage # more configurable... __PACKAGE__->load_plugin( 'Web::Auth' => { module => 'Facebook', on_finished => sub { my ($c, $token, $user) = @_; ... } } );
Amon2::Plugin::Web::Auth is authentication engine for Amon2.
THIS MODULE IS EXPERIMENTAL STATE. SOME API CHANGES WITHOUT NOTICE.
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', ... } );
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().
$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.
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.
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"; }
Tokuhiro Matsuno <tokuhirom AAJKLFJEF GMAIL COM>
Copyright (C) Tokuhiro Matsuno
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Amon2::Auth, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Amon2::Auth
CPAN shell
perl -MCPAN -e shell install Amon2::Auth
For more information on module installation, please visit the detailed CPAN module installation guide.