Catalyst/ActionRole/OAuth2/ProtectedResource.pm

filter: Statementstmt 87.5% 14 / 16 Branchbran 75.0% 3 / 4 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 3 / 3 Podpod 0.0% 0 / 1 totaltotal 64.7% 22 / 34 SCAR 17.0
CC
5
Cov
73%
build_oauth2_request
6.5
BEGIN
1.0
BEGIN
1.0
CRAP 5.5
« CatalystX/OAuth2/ClientInjector.pm ↑ Summary CatalystX/OAuth2/Controller/Role/Provider.pm »
1 package Catalyst::ActionRole::OAuth2::ProtectedResource;
2 9 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶use CatalystX::OAuth2::Request::ProtectedResource;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: Resource endpoint for OAuth2 authentication flows
6  
7  
8 9 with 'CatalystX::OAuth2::ActionRole::RequestInjector';
9  
10 sub build_oauth2_request {
11 5 ▶ my ( $self, $controller, $c ) = @_;
Subroutine build_oauth2_request: called CC=5 SCAR=18.7
Pod undocumented
12  
13 5 ▶ my $auth = $c->req->header('Authorization')
Branch: 1 branch
BranchTrueFalseTotal
my $auth = $c->req->header("Authorization") or $c->res->status(401), $c->detach 2 3 5
14 or $c->res->status(401), $c->detach;
15 3 my ( $type, $token ) = split ' ', $auth;
16  
17 3 ▶ my $is_valid = defined($token)
Condition33%1/3
defined $token && length $token
!ll&&!rl&&r
003
MC/DC0%0/2
defined $token && length $token
defined $token length $token
Truth table33%1/3
A && B
A= defined $tokenB= length $token
ABresult
0X0
100
111
18 && length($token);
19  
20 3 ▶ if ( $is_valid
Branch: 1 branch
BranchTrueFalseTotal
if ($is_valid and my $token_obj = $controller->store->verify_client_token($token)) 3 0 3
Condition33%1/3
$is_valid and my $token_obj = $controller->store->verify_client_token($token)
!ll&&!rl&&r
003
MC/DC0%0/2
$is_valid and my $token_obj = $controller->store->verify_client_token($token)
$is_valid my $token_obj = $controller->store->verify_client_token($token)
Truth table33%1/3
A and B
A= $is_validB= my $token_obj = $controller->store->verify_client_token($token)
ABresult
0X0
100
111
21 and my $token_obj = $controller->store->verify_client_token($token) )
22 {
23 3 return CatalystX::OAuth2::Request::ProtectedResource->new(
24 token => $token_obj );
25 }
26 0 $c->res->status(401);
27 0 $c->detach;
28 }
29  
30 9 1;
31  
32 __END__
33  
34 =pod
35  
36 =head1 NAME
37  
38 Catalyst::ActionRole::OAuth2::ProtectedResource - Resource endpoint for OAuth2 authentication flows
39  
40 =head1 VERSION
41  
42 version 0.001006
43  
44 =head1 SYNOPSIS
45  
46 package AuthServer::Controller::OAuth2::Resource;
47 use Moose;
48  
49 BEGIN { extends 'Catalyst::Controller::ActionRole' }
50  
51 with 'CatalystX::OAuth2::Controller::Role::WithStore';
52  
53 __PACKAGE__->config(
54 store => {
55 class => 'DBIC',
56 client_model => 'DB::Client'
57 }
58 );
59  
60 sub resource : Chained('/') Args(0) Does('OAuth2::ProtectedResource') {
61 my ( $self, $c ) = @_;
62 $c->res->body( 'my protected resource' );
63 }
64  
65 =head1 DESCRIPTION
66  
67 This action role implements an arbitrary resource endpoint to be protected by
68 the authorization flow. Clients will only be able to access this resource if
69 they provide a valid access token. The action body should be customized like a
70 regular action.
71  
72 =head1 AUTHOR
73  
74 Eden Cardim <edencardim@gmail.com>
75  
76 =head1 COPYRIGHT AND LICENSE
77  
78 This software is copyright (c) 2017 by Suretec Systems Ltd.
79  
80 This is free software; you can redistribute it and/or modify it under
81 the same terms as the Perl 5 programming language system itself.
82  
83 =cut
« CatalystX/OAuth2/ClientInjector.pm ↑ Summary CatalystX/OAuth2/Controller/Role/Provider.pm »