Skip to content

Instantly share code, notes, and snippets.

@jadeallenx
Created July 25, 2012 16:43
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 jadeallenx/3177150 to your computer and use it in GitHub Desktop.
Save jadeallenx/3177150 to your computer and use it in GitHub Desktop.
Simple persistent Dancer authorization service
use Dancer;
use Dancer::Plugin::Database;
# Using DBD::SQLite database with
# create table authorized_users (
# username text,
# password text
# );
#
# insert into authorized_users (username, password) VALUES ('fred', 'somehash');
#
# See Dancer::Plugin::Database for more Dancer/DBI magic
set plugins => { 'Database' => { driver => 'SQLite', database => "./auth.sq3" } };
post '/auth' => sub {
if ( database->quick_select('authorized_users',
{ username => params->{username},
password => params->{password} }) ) {
return status 'ok';
}
else {
return send_error("Forbidden", 403);
}
};
start;
__END__
# $ cpanm DBD::SQLite Dancer::Plugin::Database Starman
#
# Startup the service with
# $ starman myauth.pl
#
# Test with
# $ curl -i -XPOST -d'username=fred&password=somehash' http://localhost:5000/auth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment