Skip to content

Commit

Permalink
began to rewrite some stuff so i can better use Dist::Milla
Browse files Browse the repository at this point in the history
sorry markus :(
  • Loading branch information
pgraemer committed Mar 17, 2015
1 parent b81c572 commit e042af8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 50 deletions.
6 changes: 5 additions & 1 deletion Build.PL
@@ -1,3 +1,7 @@
# This Build.PL for Mojolicious-Plugin-HttpBasicAuth was generated by Dist::Zilla::Plugin::ModuleBuildTiny 0.009.
use strict;
use warnings;

use 5.008005;
use Module::Build::Tiny 0.030;
use Module::Build::Tiny 0.039;
Build_PL();
8 changes: 4 additions & 4 deletions LICENSE
@@ -1,4 +1,4 @@
This software is copyright (c) 2014 by Patrick Grämer, Markus Michel.
This software is copyright (c) 2015 by Patrick Grämer <pgraemer@cpan.org>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
Expand All @@ -12,7 +12,7 @@ b) the "Artistic License"

--- The GNU General Public License, Version 1, February 1989 ---

This software is Copyright (c) 2014 by Patrick Grämer, Markus Michel.
This software is Copyright (c) 2015 by Patrick Grämer <pgraemer@cpan.org>.

This is free software, licensed under:

Expand All @@ -22,7 +22,7 @@ This is free software, licensed under:
Version 1, February 1989

Copyright (C) 1989 Free Software Foundation, Inc.
51 Franklin St, Suite 500, Boston, MA 02110-1335 USA
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Expand Down Expand Up @@ -272,7 +272,7 @@ That's all there is to it!

--- The Artistic License 1.0 ---

This software is Copyright (c) 2014 by Patrick Grämer, Markus Michel.
This software is Copyright (c) 2015 by Patrick Grämer <pgraemer@cpan.org>.

This is free software, licensed under:

Expand Down
13 changes: 6 additions & 7 deletions META.json
@@ -1,17 +1,16 @@
{
"abstract" : "Http-Basic-Authentication implementation for Mojolicious",
"author" : [
"Patrick Gr\u00e4mer, <pgraemer@cpan.org>, L<http://graemer.org>.",
"Markus Michel, <mmichel@cpan.org>, L<http://markusmichel.org>."
"Patrick Grämer <pgraemer@cpan.org>"
],
"dynamic_config" : 0,
"generated_by" : "Dist::Milla version v1.0.4, Dist::Zilla version 5.012, CPAN::Meta::Converter version 2.133380",
"generated_by" : "Dist::Zilla version 5.032, Dist::Milla version v1.0.14, CPAN::Meta::Converter version 2.143240",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
"version" : 2
},
"name" : "Mojolicious-Plugin-HttpBasicAuth",
"no_index" : {
Expand All @@ -27,11 +26,12 @@
"prereqs" : {
"configure" : {
"requires" : {
"Module::Build::Tiny" : "0.030"
"Module::Build::Tiny" : "0.039"
}
},
"develop" : {
"requires" : {
"Dist::Milla" : "v1.0.14",
"Test::Pod" : "1.41"
}
},
Expand Down Expand Up @@ -63,8 +63,7 @@
},
"version" : "0.11",
"x_contributors" : [
"Patrick Gr\u00e4mer <pgraemer@cpan.org>",
"Markus Michel <mmichel@cpan.org>"
"Markus Michel <mmichel@cpan.org>",
]
}

51 changes: 28 additions & 23 deletions README.md
@@ -1,9 +1,9 @@
# Mojolicious::Plugin::HttpBasicAuth
# NAME

Http-Basic-Authentication implementation for Mojolicious
Mojolicious::Plugin::HttpBasicAuth - Http-Basic-Authentication implementation for Mojolicious

# SYNOPSIS
```perl

# in your startup
$self->plugin(
'http_basic_auth', {
Expand All @@ -13,7 +13,6 @@ Http-Basic-Authentication implementation for Mojolicious
my $password = shift;
my $realm = shift;
return 1 if($realm eq 'Evergreen Terrace' && $loginname eq 'Homer' && $password eq 'Marge');

return 0;
},
realm => 'Evergreen Terrace'
Expand All @@ -26,17 +25,14 @@ Http-Basic-Authentication implementation for Mojolicious
return unless $self->basic_auth(\%options);
$self->render();
}

# or bridged
my $foo = $r->bridge('/bridge')->to(cb => sub {
my $self = shift;
# Authenticated
return unless $self->basic_auth({realm => 'Castle Bridge', validate => sub {return 1;}});
});
$foo->route('/bar')->to(controller => 'foo', action => 'bar');
```



# DESCRIPTION

Expand All @@ -47,13 +43,13 @@ Http-Basic-Authentication implementation for Mojolicious
[Mojolicious::Plugin::HttpBasicAuth](https://metacpan.org/pod/Mojolicious::Plugin::HttpBasicAuth) supports the following options.

## realm
```perl

$self->plugin('http_basic_auth', {realm => 'My Castle!'});
```

HTTP-Realm, defaults to 'WWW'

## validate
```perl

$self->plugin('http_basic_auth', {
validate => sub {
my $c = shift;
Expand All @@ -64,11 +60,11 @@ HTTP-Realm, defaults to 'WWW'
return 0;
}
});
```
Validation callback to verify user. This option is __mandatory__.

Validation callback to verify user. This option is **mandatory**.

## invalid
```perl

$self->plugin('http_basic_auth', {
invalid => sub {
my $controller = shift;
Expand All @@ -79,17 +75,17 @@ Validation callback to verify user. This option is __mandatory__.
);
}
});
```
Callback for invalid requests, default can be seen here. Return values are dispatched to ["respond_to" in Mojolicious::Controller](https://metacpan.org/pod/Mojolicious::Controller#respond_to)

Callback for invalid requests, default can be seen here. Return values are dispatched to ["respond\_to" in Mojolicious::Controller](https://metacpan.org/pod/Mojolicious::Controller#respond_to)

# HELPERS

[Mojolicious::Plugin::HttpBasicAuth](https://metacpan.org/pod/Mojolicious::Plugin::HttpBasicAuth) implements the following helpers.

## basic\_auth
```perl

return unless $self->basic_auth({realm => 'Kitchen'});
```

All default options can be overwritten in every call.

# METHODS
Expand All @@ -98,19 +94,28 @@ All default options can be overwritten in every call.
[Mojolicious::Plugin](https://metacpan.org/pod/Mojolicious::Plugin) and implements the following new ones.

## register
```perl

my $route = $plugin->register(Mojolicious->new);
my $route = $plugin->register(Mojolicious->new, {realm => 'Fort Knox', validate => sub {
return 0;
}});
```

Register renderer and helper in [Mojolicious](https://metacpan.org/pod/Mojolicious) application.

# SEE ALSO

[Mojolicious](https://metacpan.org/pod/Mojolicious), [Mojolicious::Guides](https://metacpan.org/pod/Mojolicious::Guides), [http://mojolicio.us](http://mojolicio.us).

# AUTHORS
# AUTHOR

Patrick Grämer <pgraemer@cpan.org>
, [http://graemer.org](http://graemer.org).

# COPYRIGHT

Copyright 2015 Patrick Grämer

# LICENSE

Patrick Grämer, <pgraemer@cpan.org>, [http://graemer.org](http://graemer.org).
Markus Michel, <mmichel@cpan.org>, [http://markusmichel.org](http://markusmichel.org).
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
42 changes: 27 additions & 15 deletions lib/Mojolicious/Plugin/HttpBasicAuth.pm
Expand Up @@ -70,18 +70,8 @@ sub _unauthorized {
}

1;
__DATA__

@@ auth/basic.html.ep
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
__END__
=pod
=encoding utf8
Expand Down Expand Up @@ -112,7 +102,7 @@ Mojolicious::Plugin::HttpBasicAuth - Http-Basic-Authentication implementation fo
return unless $self->basic_auth(\%options);
$self->render();
}
# or bridged
my $foo = $r->bridge('/bridge')->to(cb => sub {
my $self = shift;
Expand Down Expand Up @@ -194,9 +184,31 @@ Register renderer and helper in L<Mojolicious> application.
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
=head1 AUTHORS
=head1 AUTHOR
Patrick Grämer E<lt>pgraemer@cpan.orgE<gt>
, L<http://graemer.org>.
=head1 COPYRIGHT
Copyright 2015 Patrick Grämer
Patrick Grämer, E<lt>pgraemer@cpan.orgE<gt>, L<http://graemer.org>.
Markus Michel, E<lt>mmichel@cpan.orgE<gt>, L<http://markusmichel.org>.
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut

__DATA__
@@ auth/basic.html.ep
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
__END__

0 comments on commit e042af8

Please sign in to comment.