[dancer-users] Basic authentication and Dancer

WK wanradt at gmail.com
Fri Feb 12 23:03:15 GMT 2016


2016-02-12 23:54 GMT+02:00 Nikos Vaggalis <nikos.vaggalis at gmail.com>:

> those variables get filled with the values you enter in the Authentication
> dialogue when it asks for a username and password

Thank you,  Nikos! Your direction toward
Plack::Middleware::Auth::Basic was good hint.

Maybe this solution has some value to others to, so I share it here.

Because my little app acts like AJAX-feeder for other pages (which are
protected with Auth basic), it is not permitted to reponse
indepentently, but only if it is called from pages behind certain
realm.

So all I needed finally, was this little app.psgi:

#!/usr/bin/env perl
use Dancer;
use Plack::Builder;
use Plack::Middleware::Auth::Basic;
use My::App;

my $app = sub {
    my $env     = shift;
    my $request = Dancer::Request->new( env => $env );
    Dancer->dance( $request );
};

builder {
  enable "Auth::Basic", realm => 'admin', authenticator => sub {
    my ( $username, $password ) = @_;
    return $username ? 1 : 0;
  };
  $app;
};


Thank you all!

-- 
Wbr,
Kõike hääd,

G


More information about the dancer-users mailing list