View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Gideon Israel Dsouza > Dancer-Plugin-Auth-Github-0.04 > Dancer::Plugin::Auth::Github



Annotate this POD


Open  1
View/Report Bugs
Module Version: 0.04   Source  


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


    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

    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
        #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" };



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.


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


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


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


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)


The plugin defines the following route handler automatically


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.


Gideon Israel Dsouza, <gideon at>,


Please report any bugs or feature requests to bug-dancer-plugin-auth-github at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


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

    perldoc Dancer::Plugin::Auth::Github

You can also look for information at:


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.


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 for more information.

syntax highlighting: