| 1 | package Mojolicious::Plugin::Web::Auth; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.17'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 0 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 0 | my ( $self, $app, $args ) = @_; | |||||||||||||||||||||||||||
| 12 | 0 | ▶ | my $module = delete $args->{module} or die "Missing mandatory parameter: module"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 13 | 0 | my $klass = join '::', __PACKAGE__, 'Site', $module; | |||||||||||||||||||||||||||
| 14 | 0 | ▶ | if ($Mojolicious::VERSION >= 5.81) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | 0 | Mojo::Loader::load_class($klass); | |||||||||||||||||||||||||||
| 16 | } else { | ||||||||||||||||||||||||||||
| 17 | 0 | Mojo::Loader->load($klass); | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | my $moniker = $klass->moniker(); | |||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $authenticate_path = delete $args->{authenticate_path} || "/auth/${moniker}/authenticate"; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args->{'authenticate_path'} || "/auth/$moniker/authenticate"
MC/DC0%0/1
delete $args->{'authenticate_path'} || "/auth/$moniker/authenticate"
delete $args->{'authenticate_path'}
Truth table0%0/2
A
A= delete $args->{'authenticate_path'}
| |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | my $callback_path = delete $args->{callback_path} || "/auth/${moniker}/callback"; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args->{'callback_path'} || "/auth/$moniker/callback"
MC/DC0%0/1
delete $args->{'callback_path'} || "/auth/$moniker/callback"
delete $args->{'callback_path'}
Truth table0%0/2
A
A= delete $args->{'callback_path'}
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # handlers | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my $on_finished = delete $args->{on_finished} or die "Missing mandatory parameter: on_finished"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $on_error = delete $args->{on_error} || sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 27 | 0 | my ( $c, $err ) = @_; | |||||||||||||||||||||||||||
| 28 | 0 | die "Authentication error in $module: $err"; | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | }; | ||||||||||||||||||||||||||
|
Condition0%0/3
delete $args->{'on_error'} || sub {
my($c, $err) = @_;
die "Authentication error in ${module}: $err";
}
MC/DC0%0/2
delete $args->{'on_error'} || sub {
my($c, $err) = @_;
die "Authentication error in ${module}: $err";
}
delete $args->{'on_error'}
sub {
my($c, $err) = @_;
die "Authentication error in ${module}: $err";
}
Truth table0%0/3
A || B
A= delete $args->{'on_error'}B= sub {
my($c, $err) = @_;
die "Authentication error in ${module}: $err";
}
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # auth object | ||||||||||||||||||||||||||||
| 32 | 0 | my $auth = $klass->new(%$args); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $app->hook( before_dispatch => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 35 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 36 | 0 | my $path = $c->req->url->path; | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ( $path->contains($authenticate_path) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 38 | 0 | my $forwarded_proto = $c->req->headers->header('x-forwarded-proto'); | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | $c->req->url->base->scheme('https') if (defined $forwarded_proto && $forwarded_proto eq 'https'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $forwarded_proto and $forwarded_proto eq "https"
MC/DC0%0/2
defined $forwarded_proto and $forwarded_proto eq "https"
defined $forwarded_proto
$forwarded_proto eq "https"
Truth table0%0/3
A and B
A= defined $forwarded_protoB= $forwarded_proto eq "https"
| |||||||||||||||||||||||||||||
| 40 | 0 | my $callback = $c->req->url->path($callback_path)->to_abs; | |||||||||||||||||||||||||||
| 41 | 0 | return $c->redirect_to( $auth->auth_uri( $c, $callback ) ); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | elsif ( $path->contains($callback_path) ) { | ||||||||||||||||||||||||||||
| 44 | return $auth->callback( $c, +{ | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | on_finished => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 46 | 0 | $on_finished->($c, @_); | |||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | on_error => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 49 | 0 | $on_error->($c, @_); | |||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||
| 51 | 0 | } ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 0 | } ); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | return $self; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | 1; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||