This file is indexed.

/usr/share/perl5/Mojolicious/Plugin/BasicAuth.pm is in libmojolicious-plugin-basicauth-perl 0.08-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package Mojolicious::Plugin::BasicAuth;

use strict;
use warnings;
use Mojo::ByteStream;

our $VERSION = '0.08';

use base 'Mojolicious::Plugin';

sub register {
    my ($plugin, $app) = @_;

    $app->renderer->add_helper(
        basic_auth => sub {
            my $self = shift;

            #
            # Sent Credentials
            my $auth = $self->req->url->to_abs->userinfo || '';

            # Required credentials
            my ($realm, $password, $username) = $plugin->_expected_auth(@_);
            my $callback = $password if ref $password eq 'CODE';

            # No credentials entered
            return $plugin->_password_prompt($self, $realm)
              if !$auth and !$callback;

            # Verification within callback
            return 1 if $callback and $callback->(split /:/, $auth, 2);

            # Verified with realm => username => password syntax
            return 1 if $auth eq ($username || '') . ":$password";

            # Not verified
            return $plugin->_password_prompt($self, $realm);
        }
    );
}

sub _expected_auth {
    my $self  = shift;
    my $realm = shift;

    return @$realm{qw/ realm password username /} if ref $realm eq "HASH";

    # realm, pass, user || realm, pass, undef || realm, callback
    return $realm, reverse @_;
}

sub _password_prompt {
    my ($self, $c, $realm) = @_;

    $c->res->headers->www_authenticate("Basic realm=$realm");
    $c->res->code(401);
    $c->rendered;

    return;
}

1;
__END__

=head1 NAME

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

=head1 DESCRIPTION

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

=head1 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;

=head1 METHODS

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

=head2 C<register>

    $plugin->register;

Register condition in L<Mojolicious> application.

=head1 SEE ALSO

L<Mojolicious>

=head1 DEVELOPMENT

L<http://github.com/tempire/mojolicious-plugin-basicauth>

=head1 VERSION

0.06

=head1 CREDITS

=over 4

=item Kirill Miazine

=back

=head1 AUTHOR

Glen Hinkle tempire@cpan.org

=cut