CatalystX/OAuth2/Request/GrantAuth.pm

filter: Statementstmt 100% 39 / 39 Branchbran 75.0% 9 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 93.3% 56 / 60 SCAR 19.5
CC
7
Cov
94%
_build_query_parameters
7.1
BEGIN
1.0
BEGIN
1.0
CRAP 7.0
« CatalystX/OAuth2/Controller/Role/WithStore.pm ↑ Summary CatalystX/OAuth2/ClientInjector.pm »
1 package CatalystX::OAuth2::Request::GrantAuth;
2 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use MooseX::SetOnce;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ABSTRACT: A catalyst request extension for approving grants
8  
9 10 with 'CatalystX::OAuth2::Grant';
10  
11 10 has user => (
12 isa => duck_type(['id']),
13 is => 'rw',
14 traits => ['SetOnce']
15 );
16 10 has user_is_valid => ( isa => 'Bool', is => 'rw', default => 0 );
17 10 has approved => (
18 isa => 'Bool',
19 is => 'rw',
20 default => 0,
21 lazy => 1,
22 predicate => 'has_approval'
23 );
24 10 has code => ( is => 'ro', required => 1 );
25 has granted_scopes =>
26 12 ▶ ( isa => 'ArrayRef', is => 'rw', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
27  
28 around _params => sub {
29 12 ▶ my $super = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
30 12 my ($self) = @_;
31 12 return ( $super->(@_), qw(code granted_scopes code approved) );
32 10 };
33  
34 sub _build_query_parameters {
35 5 ▶ my ($self) = @_;
Subroutine _build_query_parameters: called CC=7 SCAR=19.6
36  
37 5 ▶ my %q = $self->has_state ? ( state => $self->state ) : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->has_state ? : 4 1 5
38  
39 5 ▶ $self->response_type eq 'code'
Branch: 1 branch
BranchTrueFalseTotal
$self->response_type eq "code" or return {"error", "unsuported_response_type", "error_description", 'this server does not support "' . $self->response_type . q[' as a method for obtaining an authorization code], %q} 0 5 5
40 or return {
41 error => 'unsuported_response_type',
42 error_description => 'this server does not support "'
43 . $self->response_type
44 . "' as a method for obtaining an authorization code",
45 %q
46 };
47  
48 5 my $store = $self->store;
49 5 ▶ my $client = $store->find_client( $self->client_id )
Branch: 1 branch
BranchTrueFalseTotal
my $client = $store->find_client($self->client_id) or return {"error", "unauthorized_client", "error_description", 'the client identified by ' . $self->client_id . ' is not authorized to access this resource'} 0 5 5
50 or return {
51 error => 'unauthorized_client',
52 error_description => 'the client identified by '
53 . $self->client_id
54 . ' is not authorized to access this resource'
55 };
56  
57 5 ▶ my $code = $store->find_client_code( $self->code, $self->client_id )
Branch: 1 branch
BranchTrueFalseTotal
my $code = $store->find_client_code($self->code, $self->client_id) or return {"error", "server_error", "error_description", "the server encountered an unexpected error condition"} 2 3 5
58 or return {
59 error => 'server_error',
60 error_description =>
61 'the server encountered an unexpected error condition'
62 };
63  
64 3 ▶ if ( $self->has_approval ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_approval) 3 0 3
65 return {
66 3 ▶ error => 'access_denied',
Branch: 1 branch
BranchTrueFalseTotal
unless $self->approved 1 2 3
67 error_description => 'the resource owner denied the request'
68 }
69 unless $self->approved;
70 2 $code->activate;
71 2 $q{code} = $code->as_string;
72 }
73  
74 2 return \%q;
75 }
76  
77 sub next_action_uri {
78 11 ▶ my ( $self, $controller, $c ) = @_;
Subroutine next_action_uri: called CC=1 SCAR=0.0
Pod undocumented
79 11 my $uri = URI->new( $c->req->oauth2->redirect_uri );
80 11 $uri->query_form( $self->query_parameters );
81 11 return $uri;
82 }
83  
84 10 1;
85  
86 __END__
87  
88 =pod
89  
90 =head1 NAME
91  
92 CatalystX::OAuth2::Request::GrantAuth - A catalyst request extension for approving grants
93  
94 =head1 VERSION
95  
96 version 0.001006
97  
98 =head1 AUTHOR
99  
100 Eden Cardim <edencardim@gmail.com>
101  
102 =head1 COPYRIGHT AND LICENSE
103  
104 This software is copyright (c) 2017 by Suretec Systems Ltd.
105  
106 This is free software; you can redistribute it and/or modify it under
107 the same terms as the Perl 5 programming language system itself.
108  
109 =cut
« CatalystX/OAuth2/Controller/Role/WithStore.pm ↑ Summary CatalystX/OAuth2/ClientInjector.pm »