CatalystX/OAuth2/Store/DBIC.pm

filter: Statementstmt 75.0% 48 / 64 Branchbran 46.1% 12 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.5% 12 / 17 Podpod 0.0% 0 / 12 totaltotal 60.5% 72 / 119 SCAR 30.6
CC
14
Cov
67%
client_endpoint
6.0
activate_client_code
6.0
deactivate_client_code
6.0
CRAP 21.3
↑ Summary Catalyst/Authentication/Credential/OAuth2.pm »
1 package CatalystX::OAuth2::Store::DBIC;
2 9 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: An interface to a DBIC-based OAuth2 store
6  
7 9 with 'CatalystX::OAuth2::Store';
8  
9 9 has app => ( is => 'ro', required => 1 );
10 9 has client_model => (
11 isa => 'Str',
12 is => 'ro',
13 required => 1
14 );
15 9 has _client_model => (
16 isa => 'DBIx::Class::ResultSet',
17 is => 'ro',
18 lazy_build => 1
19 );
20 9 has endpoint_field => ( isa => 'Str', is => 'ro', default => 'endpoint' );
21 9 has refresh_relation =>
22 ( isa => 'Str', is => 'ro', default => 'refresh_tokens' );
23 9 has token_relation => ( isa => 'Str', is => 'ro', default => 'tokens' );
24 9 has code_relation => ( isa => 'Str', is => 'ro', default => 'codes' );
25 9 has code_activation_field =>
26 ( isa => 'Str', is => 'ro', default => 'is_active' );
27  
28 sub _build__client_model {
29 9 ▶ my ($self) = @_;
Subroutine _build__client_model: called CC=1 SCAR=0.0
30 9 return $self->app->model( $self->client_model );
31 }
32  
33 sub find_client {
34 18 ▶ my ( $self, $id ) = @_;
Subroutine find_client: called CC=1 SCAR=0.0
Pod undocumented
35 18 $self->_client_model->find($id);
36 }
37  
38 sub client_endpoint {
39 0 ▶ my ( $self, $id ) = @_;
Subroutine client_endpoint: not called CC=2 SCAR=17.9
Pod undocumented
40 0 ▶ my $client = $self->find_client($id)
Branch: 1 branch
BranchTrueFalseTotal
my $client = $self->find_client($id) or return 0 0 0
41 or return;
42 0 return $client->get_column( $self->endpoint_field );
43 }
44  
45 sub _code_rs {
46 14 ▶ my ( $self, $id ) = @_;
Subroutine _code_rs: called CC=3 SCAR=11.0
47 14 ▶ return $self->_client_model->related_resultset( $self->code_relation )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 11 3 14
48 unless defined($id);
49 3 ▶ my $client = $self->find_client($id)
Branch: 1 branch
BranchTrueFalseTotal
my $client = $self->find_client($id) or return 0 3 3
50 or return;
51 3 return $client->related_resultset( $self->code_relation );
52 }
53  
54 sub create_client_code {
55 3 ▶ my ( $self, $id ) = @_;
Subroutine create_client_code: called CC=1 SCAR=0.0
Pod undocumented
56 3 $self->_code_rs($id)->create( {} );
57 }
58  
59 sub find_client_code {
60 11 ▶ my ( $self, $code, $id ) = @_;
Subroutine find_client_code: called CC=2 SCAR=6.9
Pod undocumented
61 11 ▶ return $id
Branch: 1 branch
BranchTrueFalseTotal
$id ? : 5 6 11
62 ? $self->_code_rs->find($code)
63 : $self->_code_rs($id)->find($code);
64 }
65  
66 sub activate_client_code {
67 0 ▶ my ( $self, $id, $code ) = @_;
Subroutine activate_client_code: not called CC=2 SCAR=17.9
Pod undocumented
68 0 ▶ my $code_row = $self->find_client_code( $id, $code )
Branch: 1 branch
BranchTrueFalseTotal
my $code_row = $self->find_client_code($id, $code) or return 0 0 0
69 or return;
70 0 $code_row->update( { $self->code_activation_field => 1 } );
71 }
72  
73 sub deactivate_client_code {
74 0 ▶ my ( $self, $id, $code ) = @_;
Subroutine deactivate_client_code: not called CC=2 SCAR=17.9
Pod undocumented
75 0 ▶ my $code_row = $self->find_client_code( $id, $code )
Branch: 1 branch
BranchTrueFalseTotal
my $code_row = $self->find_client_code($id, $code) or return 0 0 0
76 or return;
77 0 $code_row->update( { $self->code_activation_field => 0 } );
78 }
79  
80 sub client_code_is_active {
81 0 ▶ my ( $self, $id ) = @_;
Subroutine client_code_is_active: not called CC=2 SCAR=17.9
Pod undocumented
82 0 ▶ my $client = $self->find_client($id)
Branch: 1 branch
BranchTrueFalseTotal
my $client = $self->find_client($id) or return 0 0 0
83 or return;
84 0 return $client->get_column( $self->code_activation_field );
85 }
86  
87 sub create_access_token {
88 3 ▶ my ( $self, $code, $with_refresh ) = @_;
Subroutine create_access_token: called CC=3 SCAR=11.0
Pod undocumented
89 3 ▶ my $code_row = $self->find_client_code($code)
Branch: 1 branch
BranchTrueFalseTotal
my $code_row = $self->find_client_code($code) or return 0 3 3
90 or return;
91 3 ▶ return $code_row->related_resultset( $self->token_relation )->create( {} )
Branch: 1 branch
BranchTrueFalseTotal
unless $with_refresh 2 1 3
92 unless $with_refresh;
93 1 my $token;
94 $code_row->result_source->storage->dbh_do(
95 sub {
96 1 ▶ my $refresh = $code_row->related_resultset( $self->refresh_relation )->create( {} );
Subroutine __ANON__: called CC=1 SCAR=0.0
97 1 $token = $refresh->create_access_token;
98 }
99 1 );
100 1 return $token;
101 }
102  
103 sub create_access_token_from_refresh {
104 1 ▶ my ( $self, $refresh ) = @_;
Subroutine create_access_token_from_refresh: called CC=2 SCAR=7.1
Pod undocumented
105 1 ▶ my $refresh_row = $self->_client_model->find_refresh($refresh)
Branch: 1 branch
BranchTrueFalseTotal
my $refresh_row = $self->_client_model->find_refresh($refresh) or return 0 1 1
106 or return;
107 1 return $refresh_row->create_access_token;
108 }
109  
110 sub find_code_from_refresh {
111 1 ▶ my ( $self, $refresh ) = @_;
Subroutine find_code_from_refresh: called CC=2 SCAR=7.1
Pod undocumented
112 1 ▶ my $refresh_row = $self->_client_model->find_refresh($refresh)
Branch: 1 branch
BranchTrueFalseTotal
my $refresh_row = $self->_client_model->find_refresh($refresh) or return 0 1 1
113 or return;
114 1 return $refresh_row->code;
115 }
116  
117 sub verify_client_secret {
118 0 ▶ my ( $self, $client_id, $access_secret ) = @_;
Subroutine verify_client_secret: not called CC=1 SCAR=6.9
Pod undocumented
119 0 my $client = $self->find_client($client_id);
120 0 return $client->client_secret eq $access_secret;
121 }
122  
123 sub verify_client_token {
124 3 ▶ my ( $self, $access_token ) = @_;
Subroutine verify_client_token: called CC=3 SCAR=11.6
Pod undocumented
125 3 my $rs = $self->_client_model;
126 3 ▶ return 0 unless defined $access_token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $access_token 0 3 3
127 3 my $token_rs = $rs->related_resultset( $self->code_relation )
128 ->related_resultset( $self->token_relation );
129 3 ▶ if(my $token = $token_rs->find($access_token)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $token_rs->find($access_token)) 3 0 3
130 3 return $token;
131 }
132 0 return 0;
133 }
134  
135 9 1;
136  
137 __END__
138  
139 =pod
140  
141 =head1 NAME
142  
143 CatalystX::OAuth2::Store::DBIC - An interface to a DBIC-based OAuth2 store
144  
145 =head1 VERSION
146  
147 version 0.001006
148  
149 =head1 AUTHOR
150  
151 Eden Cardim <edencardim@gmail.com>
152  
153 =head1 COPYRIGHT AND LICENSE
154  
155 This software is copyright (c) 2017 by Suretec Systems Ltd.
156  
157 This is free software; you can redistribute it and/or modify it under
158 the same terms as the Perl 5 programming language system itself.
159  
160 =cut
↑ Summary Catalyst/Authentication/Credential/OAuth2.pm »