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 >},
    ...
);
  • namespace - default 'Mojolicious::Plugin::RoutesAuthDBI',

  • controller - module controller name, default 'OAuth2',

  • providers - hashref. required.

    providers => {google=>{key=> ..., secret=>..., }, ...},

    See Mojolicious::Plugin::OAuth2. But two additional parameters (keys of provider hash) are needs:

    • profile_url abs url string

      profile_url=> 'https://www.googleapis.com/oauth2/v1/userinfo',
    • profile_query coderef

      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 query params.

  • pos - hashref

    SQL-dictionary for DBI statements. See Mojolicious::Plugin::RoutesAuthDBI::POS::OAuth2.

Defaults

oauth = > {
  namespace => 'Mojolicious::Plugin::RoutesAuthDBI',
  module => 'OAuth2',
  pos => {
    namespace => 'Mojolicious::Plugin::RoutesAuthDBI',
    module => 'POS::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.

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 name 'oauth-login'. This route accept param 'redirect' and will use for $c->redirect_to after success oauith and also failed oauth with out param 'err'.

/logout

Clear session and redirect to param 'redirect' || '/'. This route has 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.