OAuth2/Profile/WebServer.pm

filter: Statementstmt 71.1% 64 / 90 Branchbran 25.0% 4 / 16 Conditioncond 27.7% 5 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 75.0% 18 / 24 Podpod 61.5% 8 / 13 totaltotal 57.5% 99 / 172 CC 16 SCAR 14.9
CC
16
Cov
59%
update_access_token
20.0
authorize_response
6.0
refresh_token_params
6.0
CRAP 4.4
« OAuth2/AccessToken.pm ↑ Summary OAuth2/Profile/Password.pm »
1 # Copyrights 2013-2019 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution Net-OAuth2. Meta-POD processed
6 # with OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Net::OAuth2::Profile::WebServer;
10 4 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 $VERSION = '0.67';
12  
13 4 ▶use base 'Net::OAuth2::Profile';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use Net::OAuth2::AccessToken;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 4 ▶use HTTP::Request ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use HTTP::Response ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶use HTTP::Status qw(HTTP_TEMPORARY_REDIRECT);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26  
27 sub init($)
28 2 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=3 SCAR=12.3
Pod undocumented
29 2 ▶ $args->{grant_type} ||= 'authorization_code';
Condition50%1/2
$args->{"grant_type"} ||= "authorization_code"
l!l
02
MC/DC0%0/1
$args->{"grant_type"} ||= "authorization_code"
$args->{"grant_type"}
Truth table50%1/2
A
A= $args->{"grant_type"}
Aresult
11
00
30 2 $self->SUPER::init($args);
31 2 $self->{NOPW_redirect} = $args->{redirect_uri};
32 2 $self->{NOPW_referer} = $args->{referer};
33 $self->{NOPW_auto_save} = $args->{auto_save}
34 0 ▶ || sub { my $token = shift; $token->changed(1) };
Subroutine __ANON__: not called CC=1 SCAR=2.6
Condition33%1/3
$args->{'auto_save'} || sub { my $token = shift(); $token->changed(1); }
l!l&&r!l&&!r
020
MC/DC0%0/2
$args->{'auto_save'} || sub { my $token = shift(); $token->changed(1); }
$args->{'auto_save'} sub { my $token = shift(); $token->changed(1); }
Truth table33%1/3
A || B
A= $args->{'auto_save'}B= sub { my $token = shift(); $token->changed(1); }
ABresult
1X1
011
000
35 2 $self;
36 }
37  
38 #-------------------
39  
40 2 ▶sub redirect_uri() {shift->{NOPW_redirect}}
Subroutine redirect_uri: called CC=1 SCAR=0.0
Pod documented
41 sub referer(;$)
42 3 ▶{ my $s = shift; @_ ? $s->{NOPW_referer} = shift : $s->{NOPW_referer} }
Subroutine referer: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 3 3
43 0 ▶sub auto_save() {shift->{NOPW_auto_save}}
Subroutine auto_save: not called CC=1 SCAR=6.9
Pod documented
44  
45 #--------------------
46  
47 sub authorize(@)
48 1 ▶{ my ($self, @req_params) = @_;
Subroutine authorize: called CC=3 SCAR=11.6
Pod documented
49  
50 # temporary, for backward compatibility warning
51 1 my $uri_base = $self->SUPER::authorize_url;
52 # my $uri_base = $self->authorize_url;
53  
54 1 ▶ my $uri = blessed $uri_base && $uri_base->isa('URI')
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($uri_base) && $uri_base->isa('URI') ? : 1 0 1
Condition33%1/3
builtin::blessed($uri_base) and $uri_base->isa("URI")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($uri_base) and $uri_base->isa("URI")
builtin::blessed($uri_base) $uri_base->isa("URI")
Truth table33%1/3
A and B
A= builtin::blessed($uri_base)B= $uri_base->isa("URI")
ABresult
0X0
100
111
55 ? $uri_base->clone : URI->new($uri_base);
56  
57 1 my $params = $self->authorize_params(@req_params);
58 1 $uri->query_form($uri->query_form, %$params);
59 1 $uri;
60 }
61  
62 # Net::OAuth2 returned the url+params here, but this should return the
63 # accessor to the parameter with this name. The internals of that code
64 # was so confused that it filled-in the params multiple times.
65 sub authorize_url()
66 1 ▶{ require Carp;
Subroutine authorize_url: called CC=1 SCAR=0.0
Pod undocumented
67 1 Carp::confess("do not use authorize_url() but authorize()! (since v0.50)");
68 }
69  
70  
71 sub authorize_response(;$)
72 0 ▶{ my ($self, $request) = @_;
Subroutine authorize_response: not called CC=2 SCAR=17.9
Pod documented
73 0 my $resp = HTTP::Response->new
74 ( HTTP_TEMPORARY_REDIRECT => 'Get authorization grant'
75 , [ Location => $self->authorize ]
76 );
77 0 ▶ $resp->request($request) if $request;
Branch: 1 branch
BranchTrueFalseTotal
if $request 0 0 0
78 0 $resp;
79 }
80  
81  
82 sub get_access_token($@)
83 0 ▶{ my ($self, $code, @req_params) = @_;
Subroutine get_access_token: not called CC=1 SCAR=6.9
Pod documented
84  
85 0 my $params = $self->access_token_params(code => $code, @req_params);
86  
87 0 my $request = $self->build_request
88 ( $self->access_token_method
89 , $self->access_token_url
90 , $params
91 );
92  
93 0 my $response = $self->request($request);
94  
95 0 Net::OAuth2::AccessToken->new
96 ( profile => $self
97 , auto_refresh => !!$self->auto_save
98 , $self->params_from_response($response, 'access token')
99 );
100 }
101  
102  
103 sub update_access_token($@)
104 0 ▶{ my ($self, $access, @req_params) = @_;
Subroutine update_access_token: not called CC=4 SCAR=30.0
Pod documented
105 0 ▶ my $refresh = $access->refresh_token
Branch: 1 branch
BranchTrueFalseTotal
my $refresh = $access->refresh_token or croak("unable to refresh token without refresh_token") 0 0 0
106 or croak 'unable to refresh token without refresh_token';
107  
108 0 my $req = $self->build_request
109 ( $self->refresh_token_method
110 , $self->refresh_token_url
111 , $self->refresh_token_params(refresh_token => $refresh, @req_params)
112 );
113  
114 0 my $resp = $self->request($req);
115 0 my %data = $self->params_from_response($resp, 'update token');
116  
117 my $token = $data{access_token}
118 0 ▶ or croak "no access token found in refresh data";
Branch: 1 branch
BranchTrueFalseTotal
my $token = $data{"access_token"} or croak("no access token found in refresh data") 0 0 0
119  
120 0 my $type = $data{token_type};
121  
122 my $exp = $data{expires_in}
123 0 ▶ or croak "no expires_in found in refresh data";
Branch: 1 branch
BranchTrueFalseTotal
my $exp = $data{"expires_in"} or croak("no expires_in found in refresh data") 0 0 0
124  
125 0 $access->update_token($token, $type, $exp+time(), $data{refresh_token});
126 }
127  
128 sub authorize_params(%)
129 1 ▶{ my $self = shift;
Subroutine authorize_params: called CC=4 SCAR=15.9
Pod undocumented
130 1 my $params = $self->SUPER::authorize_params(@_);
131 1 ▶ $params->{response_type} ||= 'code';
Condition50%1/2
$params->{"response_type"} ||= "code"
l!l
01
MC/DC0%0/1
$params->{"response_type"} ||= "code"
$params->{"response_type"}
Truth table50%1/2
A
A= $params->{"response_type"}
Aresult
11
00
132  
133 # should not be required: usually the related between client_id and
134 # redirect_uri is fixed to avoid security issues.
135 1 my $r = $self->redirect_uri;
136 1 ▶ $params->{redirect_uri} ||= $r if $r;
Branch: 1 branch
BranchTrueFalseTotal
if $r 0 1 1
Condition0%0/3
$params->{"redirect_uri"} ||= $r
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{"redirect_uri"} ||= $r
$params->{"redirect_uri"} $r
Truth table0%0/3
A ||= B
A= $params->{"redirect_uri"}B= $r
ABresult
1X1
011
000
137  
138 1 $params;
139 }
140  
141 sub access_token_params(%)
142 1 ▶{ my $self = shift;
Subroutine access_token_params: called CC=2 SCAR=7.4
Pod undocumented
143 1 my $params = $self->SUPER::access_token_params(@_);
144 1 ▶ $params->{redirect_uri} ||= $self->redirect_uri;
Condition33%1/3
$params->{"redirect_uri"} ||= $self->redirect_uri
l!l&&r!l&&!r
001
MC/DC0%0/2
$params->{"redirect_uri"} ||= $self->redirect_uri
$params->{"redirect_uri"} $self->redirect_uri
Truth table33%1/3
A ||= B
A= $params->{"redirect_uri"}B= $self->redirect_uri
ABresult
1X1
011
000
145 1 $params;
146 }
147  
148 sub refresh_token_params(%)
149 0 ▶{ my $self = shift;
Subroutine refresh_token_params: not called CC=2 SCAR=17.9
Pod undocumented
150 0 my $params = $self->SUPER::refresh_token_params(@_);
151 0 ▶ $params->{grant_type} ||= 'refresh_token';
Condition0%0/2
$params->{"grant_type"} ||= "refresh_token"
l!l
00
MC/DC0%0/1
$params->{"grant_type"} ||= "refresh_token"
$params->{"grant_type"}
Truth table0%0/2
A
A= $params->{"grant_type"}
Aresult
11
00
152 0 $params;
153 }
154  
155 #--------------------
156  
157 sub build_request($$$)
158 3 ▶{ my $self = shift;
Subroutine build_request: called CC=2 SCAR=7.4
Pod documented
159 3 my $request = $self->SUPER::build_request(@_);
160  
161 3 ▶ if(my $r = $self->referer)
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $self->referer) 0 3 3
162 0 { $request->header(Referer => $r);
163 }
164  
165 3 $request;
166 }
167  
168 #--------------------
169  
170 4 1;
« OAuth2/AccessToken.pm ↑ Summary OAuth2/Profile/Password.pm »