Gideon Israel Dsouza > Dancer-Plugin-Auth-Github-0.03 > Dancer::Plugin::Auth::Github

Download:
Dancer-Plugin-Auth-Github-0.03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.03   Source   Latest Release: Dancer-Plugin-Auth-Github-0.04

NAME ^

Dancer::Plugin::Auth::Github - Authenticate with Github

SYNOPSIS ^

    package YourDancerApplication;

    use Dancer ':syntax';
    use Dancer::Plugin::Auth::Github;

    #You must use a session backend. 
    #You should be able to use any backend support by dancer.
    set 'session'      => 'Simple';
    
    #make sure you call this first.
    #initializes the config
    auth_github_init();

    hook before => sub {
        #we don't want to be in a redirect loop
        return if request->path =~ m{/auth/github/callback};
        if (not session('github_user')) {
            redirect auth_github_authenticate_url;
        }
    };

    #by default success will redirect to this route
    get '/' => sub {
        "Hello, ".session('github_user')->{'login'};
        #For all the github_user properties
        #look at http://developer.github.com/v3/users/
        #See the Response for "Get the authenticated user"
    };

    #additionally the plugin adds session('github_access_token')
    #so you can use it if you're doing other things with GitHub Api.

    #by default authentication failure will redirect to this route
    get '/auth/github/failed' => sub { return "Github authentication Failed" };

    ...

CONCEPT ^

This plugin helps you setup authentication with github OAuth api in your dancer application. It has a helper method that returns the URL you must redirect to for authentication with github, it then defines a callback that handles the rest and if the user was authenticated, his/her info is stored in a session object session('github_user'). The plugin also adds session('github_access_token) if you're doing anything else with github api.

PREREQUESITES ^

In order for this plugin to work, you need the following:

EXPORT ^

The plugin exports the following symbols to your application's namespace:

auth_github_init

This function should be called before all your route handlers. It loads up the configuration from your config.yml

auth_github_authenticate_url

This function returns an URL that is used to authenticate with github You could put it in a hook like this:

     hook 'before' => sub {
        # we don't want a redirect loop here
        #Github will call /auth/github/callback once the user is authenticated
        return if request->path =~ m{/auth/github/callback};
    
        if (not session('github_user')) {
            redirect auth_github_authenticate_url();
        }
    };

(See this page for more on before hooks)

ROUTE HANDLERS ^

The plugin defines the following route handler automatically

/auth/github/callback

When a user authenticates on Github, Github redirects back to this url. (Note: You must set the callback url to this one). The route handler will save the access token and then retrieve the authenticated user's information in the session.

If the authentication succeeded, then the plugin will redirect to url setup in the config : github_auth_success, if it failed, then the user is redirected to github_auth_fail. By default github_auth_success = / and github_auth_fail = "/auth/github/failed"

When the authentication succeeds two session objects are created. session('github_user') . For all the github_user properties see this page. session('github_access_token') is also created, if you need to do other things with the api.

AUTHOR ^

Gideon Israel Dsouza, <gideon at cpan.org>, http://www.gideondsouza.com

BUGS ^

Please report any bugs or feature requests to bug-dancer-plugin-auth-github at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer-Plugin-Auth-Github. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Dancer::Plugin::Auth::Github

You can also look for information at:

ACKNOWLEDGEMENTS ^

This project is more or less a port of Dancer::Plugin::Auth::Twitter written by Alexis Sukrieh which itself is a port of Catalyst::Authentication::Credential::Twitter written by Jesse Stay.

LICENSE AND COPYRIGHT ^

Copyright 2013 Gideon Israel Dsouza.

This project is open source here on github.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

syntax highlighting: