Skip to content

Instantly share code, notes, and snippets.

@gideondsouza
Created September 10, 2013 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gideondsouza/6508472 to your computer and use it in GitHub Desktop.
Save gideondsouza/6508472 to your computer and use it in GitHub Desktop.
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" };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment