Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
97 lines (59 sloc) 1.62 KB

NAME

Mojolicious::Plugin::BasicAuth - Basic HTTP Auth Helper

DESCRIPTION

Mojolicous::Plugin::BasicAuth is a helper for basic http authentication.

USAGE

use Mojolicious::Lite;

plugin 'basic_auth';

get '/' => sub {
    my $self = shift;

    return $self->render_text('ok')
      if $self->basic_auth(
              realm => sub { return 1 if "@_" eq 'username password' }
      );
};

app->start;

Example of authed index page with Mojolicious

# MyApp.pm
use Mojo::Base 'Mojolicious';
sub startup {
    my $self = shift;
    $self->plugin('basic_auth');

    my $r = $self->routes;

    # a means authentication required routes
    $a = $r->bridge('/')->to('Root#auth');

    $a->get('/')->to('Root#auth');
}

# MyApp/Root.pm
use Mojo::Base 'Mojolicious::Controller';

sub auth {
    my $self = shift;

    return 1 if $self->basic_auth(
            realm => sub {
                return 1 if "@_" eq 'username password'
            }
        );
}

sub index {
    my $self = shift;

    $self->render('hello world');
}

METHODS

Mojolicious::Plugin::BasicAuth inherits all methods from Mojolicious::Plugin and implements the following new ones.

register

$plugin->register;

Register condition in Mojolicious application.

SEE ALSO

Mojolicious

DEVELOPMENT

http://github.com/tempire/mojolicious-plugin-basicauth

VERSION

0.06

CREDITS

Kirill Miazine

AUTHOR

Glen Hinkle <tempire@cpan.org>