Created
July 25, 2012 16:43
-
-
Save jadeallenx/3177150 to your computer and use it in GitHub Desktop.
Simple persistent Dancer authorization service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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