Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I want to point "my $app" to the script "plack_app_cgibin.pl" taken from Gabor's
https://perlmaven.com/plack-app-cgibin
so that when calling a cgi script it first athenticates with a token and the calls the cgi script in the cgi-bin folder. Is that possible?
my $app = sub { return [ 200, [], [ "Hello World" ] ]; }; use Plack::Builder; builder { enable "JSONP"; enable "Auth::Basic", authenticator => sub { ... }; enable "Deflater"; $app; };

Replies are listed 'Best First'.
Re: Plack::Builder point to script
by karlgoethebier (Abbot) on Jul 19, 2023 at 18:05 UTC
    «Is that possible?»

    Have you tried it? But I think it works - the code is practically like the example from the Plack Handbook page 22ff. From ibidem:

    Just like other middleware, using Auth::Basic middleware is quite simple:

    use Plack::Builder; my $app = sub { ... }; builder { enable "Auth::Basic", authenticator => sub { my($username, $password) = @_; return $username eq 'admin' && $password eq 'foobar'; }; $app; };

    This adds a basic authentication to your application $app, and the user admin can sign in with the password foobar and nobody else. The successful signed-in user gets REMOTE_USER set in PSGI $env hash so it can be used in the applications and is logged using the standard AccessLog middleware.

    «The Crux of the Biscuit is the Apostrophe»