Доброго всем

Mojolicious::Plugin::RoutesAuthDBI::OAuth

¡ ¡ ¡ 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 'OAuth'.

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 => 'OAuth',
  },

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

There are number of app routes on this controller:

/oauth/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'.

/oauth/detach/:site

Remove attached oauth user to profile. Stash site and param 'redirect' as above. Route has builtin name 'oauth-detach'.

/oauth/data

Get remote oauth data site only configured.

POST /oauth/profile/:site

Usefull for cordova mobile app oauth connect.

IN: json data {access_token="..."}> that got from oauth authorize_url API request.

OUT: stored remote oauth API profile.

<trust admin option>/oauth/conf

The "trust" in Mojolicious::Plugin::RoutesAuthDBI::Admin option.

Returns text dump current hash of "providers" in Mojolicious::Plugin::OAuth2.

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.