Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3699174
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:04:16+00:00 2026-05-19T05:04:16+00:00

I would like to have my Plack app try several different means of authorizing

  • 0

I would like to have my Plack app try several different means of authorizing the user. Specifically, check if the user is already authorized via a session cookie, then check for Digest authentication and then fall back to Basic.

I figured I could just enable a bunch of Auth handlers in the order I wanted them to be checked (Session, Digest, Basic). Unfortunately, the way that Plack::Middleware::Auth::Digest and Plack::Middleware::Auth::Basic are written they both return 401 if digest or basic auth doesn’t exist, respectively.

How is this normally dealt with in Plack?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T05:04:16+00:00Added an answer on May 19, 2026 at 5:04 am

    I do not have an implementation but I think I have the approach. You can do this “in-line” with Plack::Middleware::Conditional. So it would look like this but you’ll have to fill in the missing conditions/tests. I didn’t see an easy/obvious way but I suspect you might. Since you have the $env to pass around you should be able to set/check HTTP_/session stuff in the order you want and keep the state for the next handler to know if it should be enabled or not.

    use Plack::Builder;
    
    my $app = sub {
        [ 200,
          [ "Content-Type" => "text/plain" ],
          [ "O HAI, PLAK!" ]
        ];
    };
    
    builder {
        enable "Session::Cookie";
        enable_if { my $env = shift;
                    # I don't know...
                } "Auth::Digest",
                    realm => "Secured", secret => "BlahBlah",
                        authenticator => sub { $_[0] eq $_[1] };
        enable_if { my $env = shift;
                    # I don't know...
                } "Auth::Basic",
                    authenticator => sub { $_[0] eq $_[1] };
        $app;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an Android App and would like to have a video file
I have created a volume controller for iTunes but I would like this app
I would like to have an ad to appear in between your app is
I have a client who would like an iphone app that allows users to
I have a vb6 multithreaded app working and i would like to use mutexes
We have an enterprise distribution of an app that we would like to distribute
I have a third party app that requires a template. I would like to
We are printing up qr-codes for our android app, and would like to have
I Have a canvas and would like to place silverlight elements within that canvas
I have two fonts, Cooper Black and Cooper Hilite. I would like to place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.