The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Plack::Middleware::DoormanAuth0 - The Auth0 login middleware.

SYNOPSIS

    use Plack::Builder;

    builder {
        enable "Session::Cookie";
        enable "DoormanAuth0",
            root_url => 'http://localhost:5000',
            scope => 'users',
            auth0_domain => 'my-app.auth0.com',
            auth0_client_secret => '...',
            auth0_client_id     => '...';

        # The app code.
        sub {
            my $env = shift;

            # Retrive the Plack::Middleware::DoormanAuth0 object
            my $doorman = $env->{'doorman.users.auth0'};

            # Check sign-in status
            my @out;
            if ($doorman->is_sign_in) {
                push @out, qq{Hi, @{[ $doorman->auth0_email ]}!}
            }
            else {
                push @out, qq{ Please login via Auth0! }
            }

            ...
        }
    };

DESCRIPTION

This middleware module implements the Auth0 OAuth2 login flow.

Before you use it, you need to create an account with Auth0, and create an app.

Auth0 will supply you with the client secret and ID, and you'll set a domain for auth. Doorman will use these secrets to validate requests.

You need to enable "Session" middleware. The implementation requires Plack::Middleware::Session and stores relevant authentication information under $env-{psgi.session}{doorman.${scope}.auth0}>, where $scope is the scope name given by you. You may inspect this variable at runtime to get the basic idea of how the middleware stores relevant information.

The Middleware will store all Auth0 User Profile attributes into the session key, where you may access them.

After that, you can invoke several methods listed down below on the object stored in $env-{'doorman.users.auth0'}>, which is of this <Plack::Middleware::DoormanAuth0> class.

METHODS

  • is_sign_in

    Return true if the current session is considered signed in.

  • auth0_email

    Return the email address of the authenticated Auth0 user.