NAME

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

DESCRIPTION

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

USAGE

Simple - Mojolicious

	# Mojolicious
	package MyApp;
	
	sub startup {
		 my $self = shift;
		 $self->plugin('basic_auth');
		 ...
	}
    
	package MyApp::Controller;
	 
	sub index {
		my $self = shift;
		return unless $self->helper( basic_auth => realm => username => 'password' );
		
		$self->render_text( 'authenticated' );
	}

Simple - Mojolicious::Lite

plugin 'basic_auth'

get '/' => sub {
	my $self = shift;
	return unless $self->helper( basic_auth => realm => username => 'password' );
	
	# Username is optional:
	# $self->helper( basic_auth => realm => 'password' );
	
	$self->render_text( 'authenticated' );
}

Simple - Hashref configuration

# or, for more wordy configuration:
get '/' => sub {
	my $self = shift;
	
	return unless
		$self->helper( basic_auth => {
			realm => 'realm',
			username => 'username',
			password => 'password'
		} );
	
	$self->render_text( 'authenticated' );
}

Advanced - Callback

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

	return unless $self->helper( basic_auth => realm => sub {
		my ($username, $password) = @_;
		return 1 if $username eq 'username' and $password eq 'password';
	} );

	$self->render_text( 'authenticated' );
};

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.02

AUTHOR

Glen Hinkle tempire@cpan.org