Mojolicious::Plugin::RoutesAuthDBI::OAuth2
¡ ¡ ¡ ALL GLORY TO GLORIA ! ! !
NAME
Mojolicious::Plugin::RoutesAuthDBI::OAuth - is a Mojolicious::Controller for oauth2 logins to project. Its has two route: for login and logout.
DB DESIGN DIAGRAM
See https://github.com/mche/Mojolicious-Plugin-RoutesAuthDBI/blob/master/Diagram.svg
SYNOPSIS
$app->plugin('RoutesAuthDBI',
...
oauth => {< options below >},
...
);
OPTIONS
namespace
Namespace (string). Defaults to 'Mojolicious::Plugin::RoutesAuthDBI'.
controller
Module controller name. Defaults to 'OAuth2'.
providers
Hashref for key/value per each need provider. Required.
providers => {google=>{key=> ..., secret=>..., }, ...},
See Mojolicious::Plugin::OAuth2. But two additional parameters (keys of provider hash) are needs:
profile_url abs url string to fetch profile info after success oauth.
profile_url=> 'https://www.googleapis.com/oauth2/v1/userinfo',
profile_query coderef which prepare additional query params for
profile_url
Example for google:
profile_query => sub { my ($c, $auth, ) = @_; { alt => 'json', access_token => $auth->{access_token}, }; },
In: $auth hash ref with access_token.
Out: hashref
profile_url
query params.
Defaults options for oauth:
oauth = > {
namespace => 'Mojolicious::Plugin::RoutesAuthDBI',
module => 'OAuth2',
},
disable oauth module
oauth => undef,
METHODS NEEDS IN PLUGIN
_routes()
This oauth controller routes. Return array of hashrefs routes records for apply route on app. Plugin internal use.
Controller routes
/login/:site
Main route of this controller. Stash site is the name of the hash key of the providers
config above. Example html link:
<a href="<%= $c->url_for('oauth-login', site=> 'google')->query(redirect=>'profile') %>">Login by google</a>
This route has builtin name 'oauth-login'. This route accept param 'redirect' and will use for $c->redirect_to after success oauith and also failed oauth clauses with param 'err'.
/detach/:site
Remove attached oauth user to profile. Stash site and param 'redirect' as above. Route has builtin name 'oauth-detach'.
/logout
Clear session and redirect to param 'redirect' || '/'. This route has builtin name 'logout'.
SEE ALSO
Mojolicious::Plugin::RoutesAuthDBI
Mojolicious::Plugin::RoutesAuthDBI::Admin
AUTHOR
Михаил Че (Mikhail Che), <mche [on] cpan.org>
BUGS / CONTRIBUTING
Please report any bugs or feature requests at https://github.com/mche/Mojolicious-Plugin-RoutesAuthDBI/issues. Pull requests also welcome.
COPYRIGHT
Copyright 2016 Mikhail Che.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.