| 1 | package Web::Solid::Auth::Listener; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Log::Any (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Plack::Request; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Plack::Response; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use HTTP::Server::PSGI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = "0.91"; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | has host => ( | ||||||||||||||||||||||||||||||||||||||||||
| 12 | is => 'ro' , | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | default => sub { 'localhost' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 15 | has port => ( | ||||||||||||||||||||||||||||||||||||||||||
| 16 | is => 'ro' , | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | default => sub { '3000' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 19 | has scheme => ( | ||||||||||||||||||||||||||||||||||||||||||
| 20 | is => 'ro' , | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | default => sub { 'http' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 23 | has path => ( | ||||||||||||||||||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | default => sub { '/callback' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 27 | has log => ( | ||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | default => sub { Log::Any->get_logger }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub redirect_uri { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
redirect_uri: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | return sprintf "%s://%s:%s%s" | |||||||||||||||||||||||||||||||||||||||||
| 36 | , $self->scheme | ||||||||||||||||||||||||||||||||||||||||||
| 37 | , $self->host | ||||||||||||||||||||||||||||||||||||||||||
| 38 | , $self->port | ||||||||||||||||||||||||||||||||||||||||||
| 39 | , $self->path; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my ($self,$auth) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $auth //= $self->auth; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$auth //= $self->auth
MC/DC0%0/2
$auth //= $self->auth
$auth
$self->auth
Truth table0%0/3
A //= B
A= $authB= $self->auth
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $host = $self->host; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $port = $self->port; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $path = $self->path; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $self->log->info("starting callback server on $host:$port$path"); | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $server = HTTP::Server::PSGI->new( | |||||||||||||||||||||||||||||||||||||||||
| 53 | host => $host, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | port => $port, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | timeout => 120, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | $server->run( | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $env = shift; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $req = Plack::Request->new($env); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $param = $req->parameters; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $state = $auth->{state}; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->log->debugf("received: %s (%s) -> %s", $req->method, $req->path, $req->query_string); | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # Check if we got the correct path | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | unless ($req->path eq $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $res = Plack::Response->new(404); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $res->content_type("text/plain"); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $res->body("No such path"); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return $res->finalize; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # Check if we got the correct state | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | unless ($req->method eq 'GET' && $param->{code} && $param->{state} eq $state ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$req->method eq "GET" and $param->{"code"} and $param->{"state"} eq $state
$req->method eq "GET" and $param->{"code"}
MC/DC0%0/3
$req->method eq "GET" and $param->{"code"} and $param->{"state"} eq $state
$req->method eq "GET"
$param->{"code"}
$param->{"state"} eq $state
Truth table0%0/4
A and B and C
A= $req->method eq "GET"B= $param->{"code"}C= $param->{"state"} eq $state
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $res = Plack::Response->new(404); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $res->content_type("text/plain"); | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $res->body("Failed to get an access_token"); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | return $res->finalize; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $data = $auth->make_access_token($param->{code}); | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ($data) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | print "Ok stored you can close this program\n"; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $res = Plack::Response->new(200); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $res->content_type("text/plain"); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $res->body("You are logged in :)"); | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return $res->finalize; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $res = Plack::Response->new(404); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $res->content_type("text/plain"); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $res->body("Failed to get an access_token"); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return $res->finalize; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||