| 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; | ||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | $VERSION = '0.65'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use LWP::UserAgent (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use URI (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use JSON qw/decode_json/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 4 | ▶ | use Carp qw/confess carp/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 4 | ▶ | use Encode qw/encode/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 4 | ▶ | use constant MIME_URLENC => 'application/x-www-form-urlencoded'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # old names still supported: | ||||||||||||||||||||||||||||
| 27 | # bearer_token_scheme => token_scheme | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub new(@) | ||||||||||||||||||||||||||||
| 30 | 2 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | $class ne __PACKAGE__ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | or carp 'you need to create an extension, not base-class '.__PACKAGE__; | ||||||||||||||||||||||||||||
| 33 | 2 | (bless {}, $class)->init( {@_} ); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # rfc6849 Appendix B, http://www.w3.org/TR/1999/REC-html401-19991224 | ||||||||||||||||||||||||||||
| 37 | sub _url_enc($) | ||||||||||||||||||||||||||||
| 38 | 4 | ▶ | { my $x = encode 'utf8', shift; # make bytes | ||||||||||||||||||||||||||
|
Subroutine
_url_enc: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 4 | $x =~ s/([^A-Za-z0-9 ])/sprintf("%%%02x", ord $1)/ge; | |||||||||||||||||||||||||||
| 40 | 4 | $x =~ s/ /+/g; | |||||||||||||||||||||||||||
| 41 | 4 | $x; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | sub init($) | ||||||||||||||||||||||||||||
| 45 | 2 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=14 SCAR=27.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | my $id = $self->{NOP_id} = $args->{client_id} | ||||||||||||||||||||||||||||
| 47 | 2 | ▶ | or carp "profile needs id"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | my $secret = $self->{NOP_secret} = $args->{client_secret} | ||||||||||||||||||||||||||||
| 49 | 2 | ▶ | or carp "profile needs secret"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | $self->{NOP_id_enc} = _url_enc $id; | |||||||||||||||||||||||||||
| 52 | 2 | $self->{NOP_secret_enc} = _url_enc $secret; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | $self->{NOP_agent} = $args->{user_agent} || LWP::UserAgent->new; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{'user_agent'} || 'LWP::UserAgent'->new
MC/DC0%0/2
$args->{'user_agent'} || 'LWP::UserAgent'->new
$args->{'user_agent'}
'LWP::UserAgent'->new
Truth table33%1/3
A || B
A= $args->{'user_agent'}B= 'LWP::UserAgent'->new
| |||||||||||||||||||||||||||||
| 55 | $self->{NOP_scheme} = $args->{token_scheme} | ||||||||||||||||||||||||||||
| 56 | 2 | ▶ | || $args->{bearer_token_scheme} || 'auth-header:Bearer'; | ||||||||||||||||||||||||||
|
Condition40%2/5
$args->{'token_scheme'} || $args->{'bearer_token_scheme'} || 'auth-header:Bearer'
$args->{"token_scheme"} or $args->{"bearer_token_scheme"}
MC/DC0%0/2
$args->{'token_scheme'} || $args->{'bearer_token_scheme'} || 'auth-header:Bearer'
$args->{"token_scheme"}
$args->{"bearer_token_scheme"}
Truth table33%1/3
A or B
A= $args->{"token_scheme"}B= $args->{"bearer_token_scheme"}
| |||||||||||||||||||||||||||||
| 57 | 2 | $self->{NOP_scope} = $args->{scope}; | |||||||||||||||||||||||||||
| 58 | 2 | $self->{NOP_state} = $args->{state}; | |||||||||||||||||||||||||||
| 59 | 2 | $self->{NOP_hd} = $args->{hd}; | |||||||||||||||||||||||||||
| 60 | 2 | ▶ | $self->{NOP_method} = $args->{access_token_method} || 'POST'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'access_token_method'} || 'POST'
MC/DC0%0/1
$args->{'access_token_method'} || 'POST'
$args->{'access_token_method'}
Truth table50%1/2
A
A= $args->{'access_token_method'}
| |||||||||||||||||||||||||||||
| 61 | 2 | ▶ | $self->{NOP_acc_param} = $args->{access_token_param} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'access_token_param'} || []
MC/DC0%0/1
$args->{'access_token_param'} || []
$args->{'access_token_param'}
Truth table50%1/2
A
A= $args->{'access_token_param'}
| |||||||||||||||||||||||||||||
| 62 | 2 | $self->{NOP_init_params} = $args->{init_params}; | |||||||||||||||||||||||||||
| 63 | 2 | $self->{NOP_grant_type} = $args->{grant_type}; | |||||||||||||||||||||||||||
| 64 | $self->{NOP_show_secret} = exists $args->{secrets_in_params} | ||||||||||||||||||||||||||||
| 65 | 2 | ▶ | ? $args->{secrets_in_params} : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | my $site = $self->{NOP_site} = $args->{site}; | |||||||||||||||||||||||||||
| 68 | 2 | foreach my $c (qw/access_token protected_resource authorize refresh_token/) | |||||||||||||||||||||||||||
| 69 | 8 | ▶ | { my $link = $args->{$c.'_url'} || $args->{$c.'_path'} || "/oauth/$c"; | ||||||||||||||||||||||||||
|
Condition100%5/5
$$args{$c . '_url'} || $$args{$c . '_path'} || "/oauth/$c"
$$args{$c . '_url'} or $$args{$c . '_path'}
MC/DC100%2/2
$$args{$c . '_url'} || $$args{$c . '_path'} || "/oauth/$c"
$$args{$c . '_url'}
$$args{$c . '_path'}
Truth table100%3/3
A or B
A= $$args{$c . '_url'}B= $$args{$c . '_path'}
| |||||||||||||||||||||||||||||
| 70 | 8 | $self->{"NOP_${c}_url"} = $self->site_url($link); | |||||||||||||||||||||||||||
| 71 | 8 | ▶ | $self->{"NOP_${c}_method"} = $args->{$c.'_method'} || 'POST'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$$args{$c . '_method'} || 'POST'
MC/DC100%1/1
$$args{$c . '_method'} || 'POST'
$$args{$c . '_method'}
Truth table100%2/2
A
A= $$args{$c . '_method'}
| |||||||||||||||||||||||||||||
| 72 | 8 | ▶ | $self->{"NOP_${c}_param"} = $args->{$c.'_param'} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$$args{$c . '_param'} || []
MC/DC0%0/1
$$args{$c . '_param'} || []
$$args{$c . '_param'}
Truth table50%1/2
A
A= $$args{$c . '_param'}
| |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | $self; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | #---------------- | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | ▶ | sub id() {shift->{NOP_id}} | ||||||||||||||||||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub id_enc() {shift->{NOP_id_enc}} | ||||||||||||||||||||||||||
|
Subroutine
id_enc: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | 2 | ▶ | sub secret() {shift->{NOP_secret}} | ||||||||||||||||||||||||||
|
Subroutine
secret: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub secret_enc() {shift->{NOP_secret_enc}} | ||||||||||||||||||||||||||
|
Subroutine
secret_enc: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 1 | ▶ | sub user_agent() {shift->{NOP_agent}} | ||||||||||||||||||||||||||
|
Subroutine
user_agent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 11 | ▶ | sub site() {shift->{NOP_site}} | ||||||||||||||||||||||||||
|
Subroutine
site: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub scope() {shift->{NOP_scope}} | ||||||||||||||||||||||||||
|
Subroutine
scope: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 1 | ▶ | sub state() {shift->{NOP_state}} | ||||||||||||||||||||||||||
|
Subroutine
state: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 1 | ▶ | sub hd() {shift->{NOP_hd}} | ||||||||||||||||||||||||||
|
Subroutine
hd: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | sub grant_type() {shift->{NOP_grant_type}} | ||||||||||||||||||||||||||
|
Subroutine
grant_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub bearer_token_scheme() {shift->{NOP_scheme}} | ||||||||||||||||||||||||||
|
Subroutine
bearer_token_scheme: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | #---------------- | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub request($@) | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | { my ($self, $request) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
request: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | #print $request->as_string; | ||||||||||||||||||||||||||||
| 98 | 0 | my $response = $self->user_agent->request($request, @_); | |||||||||||||||||||||||||||
| 99 | #print $response->as_string; | ||||||||||||||||||||||||||||
| 100 | #$response; | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | sub request_auth(@) | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | { my ($self, $token) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
request_auth: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 106 | 0 | my $request; | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | if(@_==1) { $request = shift } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | else | ||||||||||||||||||||||||||||
| 109 | 0 | { my ($method, $uri, $header, $content) = @_; | |||||||||||||||||||||||||||
| 110 | 0 | $request = HTTP::Request->new | |||||||||||||||||||||||||||
| 111 | ( $method => $self->site_url($uri) | ||||||||||||||||||||||||||||
| 112 | , $header, $content | ||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 0 | $self->add_token($request, $token, $self->bearer_token_scheme); | |||||||||||||||||||||||||||
| 116 | 0 | $self->request($request); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | #-------------------- | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | sub site_url($@) | ||||||||||||||||||||||||||||
| 122 | 10 | ▶ | { my ($self, $path) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
site_url: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 10 | ▶ | my @params = @_==1 && ref $_[0] eq 'HASH' ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 124 | 10 | my $site = $self->site; | |||||||||||||||||||||||||||
| 125 | 10 | ▶ | my $uri = $site ? URI->new_abs($path, $site) : URI->new($path); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 10 | ▶ | $uri->query_form($uri->query_form, @params) if @params; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 10 | $uri; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | sub add_token($$$) | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | { my ($self, $request, $token, $bearer) = @_; | ||||||||||||||||||||||||||
|
Subroutine
add_token: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | 0 | my $access = $token->access_token; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | my ($scheme, $opt) = split ':', $bearer; | |||||||||||||||||||||||||||
| 136 | 0 | $scheme = lc $scheme; | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | if($scheme eq 'auth-header') | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 138 | { # Specs suggest using Bearer or OAuth2 for this value, but OAuth | ||||||||||||||||||||||||||||
| 139 | # appears to be the de facto accepted value. | ||||||||||||||||||||||||||||
| 140 | # Going to use OAuth until there is wide acceptance of something else. | ||||||||||||||||||||||||||||
| 141 | 0 | ▶ | my $auth_scheme = $opt || 'OAuth'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opt || 'OAuth'
MC/DC0%0/1
$opt || 'OAuth'
$opt
Truth table0%0/2
A
A= $opt
| |||||||||||||||||||||||||||||
| 142 | 0 | $request->headers->header(Authorization => "$auth_scheme $access"); | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | elsif($scheme eq 'uri-query') | ||||||||||||||||||||||||||||
| 145 | 0 | ▶ | { my $query_param = $opt || 'oauth_token'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opt || 'oauth_token'
MC/DC0%0/1
$opt || 'oauth_token'
$opt
Truth table0%0/2
A
A= $opt
| |||||||||||||||||||||||||||||
| 146 | 0 | $request->uri->query_form($request->uri->query_form | |||||||||||||||||||||||||||
| 147 | , $query_param => $access); | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | elsif($scheme eq 'form-body') | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | { $request->headers->content_type eq MIME_URLENC | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | or die "embedding access token in request body is only valid " | ||||||||||||||||||||||||||||
| 152 | . "for 'MIME_URLENC' content type"; | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | my $query_param = $opt || 'oauth_token'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opt || 'oauth_token'
MC/DC0%0/1
$opt || 'oauth_token'
$opt
Truth table0%0/2
A
A= $opt
| |||||||||||||||||||||||||||||
| 155 | 0 | my $content = $request->content; | |||||||||||||||||||||||||||
| 156 | 0 | ▶ | $request->add_content(($content && length $content ? '&' : '') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$content and length $content
MC/DC0%0/2
$content and length $content
$content
length $content
Truth table0%0/3
A and B
A= $contentB= length $content
| |||||||||||||||||||||||||||||
| 157 | . uri_escape($query_param).'='.uri_escape($access)); | ||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | else | ||||||||||||||||||||||||||||
| 160 | 0 | { carp "unknown bearer schema $bearer"; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | $request; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | sub build_request($$$) | ||||||||||||||||||||||||||||
| 168 | 3 | ▶ | { my ($self, $method, $uri_base, $params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
build_request: called CC=7 SCAR=20.0
Pod
documented
| |||||||||||||||||||||||||||||
| 169 | 3 | ▶ | my %params = ref $params eq 'HASH' ? %$params : @$params; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # rfc6749 section "2.3.1. Client Password" | ||||||||||||||||||||||||||||
| 172 | # The Auth Header is always supported, but client_id/client_secret as | ||||||||||||||||||||||||||||
| 173 | # parameters may be as well. We do both when ->new(secrets_in_params) | ||||||||||||||||||||||||||||
| 174 | # to support old servers. | ||||||||||||||||||||||||||||
| 175 | delete @params{qw/client_id client_secret/} | ||||||||||||||||||||||||||||
| 176 | 3 | ▶ | unless $self->{NOP_show_secret}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 3 | my $request; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 3 | ▶ | if($method eq 'POST') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 181 | 1 | { my $p = URI->new('http:'); # taken from HTTP::Request::Common | |||||||||||||||||||||||||||
| 182 | 1 | $p->query_form(%params); | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 1 | $request = HTTP::Request->new | |||||||||||||||||||||||||||
| 185 | ( $method => $uri_base | ||||||||||||||||||||||||||||
| 186 | , [Content_Type => MIME_URLENC] | ||||||||||||||||||||||||||||
| 187 | , $p->query | ||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | elsif($method eq 'GET') | ||||||||||||||||||||||||||||
| 191 | 2 | ▶ | { my $uri = blessed $uri_base && $uri_base->isa('URI') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($uri_base) and $uri_base->isa("URI")
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")
| |||||||||||||||||||||||||||||
| 192 | ? $uri_base->clone : URI->new($uri_base); | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 2 | $uri->query_form($uri->query_form, %params); | |||||||||||||||||||||||||||
| 195 | 2 | $request = HTTP::Request->new($method, $uri); | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | else | ||||||||||||||||||||||||||||
| 198 | 0 | { confess "unknown request method $method"; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 3 | my $uri = $request->uri; | |||||||||||||||||||||||||||
| 202 | 3 | my $head = $request->headers; | |||||||||||||||||||||||||||
| 203 | 3 | $request->protocol('HTTP/1.1'); | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | # 2016-01-15 Instagram does not like the portnumber to appear | ||||||||||||||||||||||||||||
| 206 | # my ($host, $port) = ($uri->host, $uri->port); | ||||||||||||||||||||||||||||
| 207 | # $host .= ':'.$port if $port != $uri->default_port; | ||||||||||||||||||||||||||||
| 208 | 3 | $head->header(Host => $uri->host); | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 3 | $head->header(Connection => 'Keep-Alive'); | |||||||||||||||||||||||||||
| 211 | 3 | $request; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | sub params_from_response($$) | ||||||||||||||||||||||||||||
| 216 | 2 | ▶ | { my ($self, $response, $why) = @_; | ||||||||||||||||||||||||||
|
Subroutine
params_from_response: called CC=9 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||
| 217 | 2 | my ($error, $content); | |||||||||||||||||||||||||||
| 218 | 2 | ▶ | $content = $response->decoded_content || $response->content if $response; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$response->decoded_content || $response->content
MC/DC0%0/2
$response->decoded_content || $response->content
$response->decoded_content
$response->content
Truth table33%1/3
A || B
A= $response->decoded_contentB= $response->content
| |||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 2 | ▶ | if(!$response) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 221 | 0 | { $error = 'no response received'; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | elsif(!$response->is_success) | ||||||||||||||||||||||||||||
| 224 | 0 | { $error = 'received error: '.$response->status_line; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | else | ||||||||||||||||||||||||||||
| 227 | { # application/json is often not correctly configured: is not | ||||||||||||||||||||||||||||
| 228 | # (yet) an apache pre-configured extension :( | ||||||||||||||||||||||||||||
| 229 | 2 | ▶ | if(my $params = eval {decode_json $content} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | { # content is JSON | ||||||||||||||||||||||||||||
| 231 | 1 | ▶ | return ref $params eq 'HASH' ? %$params : @$params; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | # otherwise form-encoded parameters (I hope) | ||||||||||||||||||||||||||||
| 235 | 1 | my $uri = URI->new; | |||||||||||||||||||||||||||
| 236 | 1 | $uri->query($content); | |||||||||||||||||||||||||||
| 237 | 1 | my @res_params = $uri->query_form; | |||||||||||||||||||||||||||
| 238 | 1 | ▶ | return @res_params if @res_params; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 0 | $error = "cannot read parameters from response"; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | ▶ | substr($content, 200) = '...' if length $content > 200; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 0 | die "failed oauth call $why: $error\n$content\n"; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | sub authorize_method() {panic} # user must use autorize url | ||||||||||||||||||||||||||||
| 248 | 0 | ▶ | sub access_token_method() {shift->{NOP_access_token_method} } | ||||||||||||||||||||||||||
|
Subroutine
access_token_method: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 249 | 1 | ▶ | sub refresh_token_method() {shift->{NOP_refresh_token_method} } | ||||||||||||||||||||||||||
|
Subroutine
refresh_token_method: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 250 | 0 | ▶ | sub protected_resource_method() {shift->{NOP_protected_resource_method} } | ||||||||||||||||||||||||||
|
Subroutine
protected_resource_method: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 1 | ▶ | sub authorize_url() {shift->{NOP_authorize_url}} | ||||||||||||||||||||||||||
|
Subroutine
authorize_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 253 | 1 | ▶ | sub access_token_url() {shift->{NOP_access_token_url}} | ||||||||||||||||||||||||||
|
Subroutine
access_token_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 254 | 1 | ▶ | sub refresh_token_url() {shift->{NOP_refresh_token_url}} | ||||||||||||||||||||||||||
|
Subroutine
refresh_token_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 255 | 0 | ▶ | sub protected_resource_url() {shift->{NOP_protected_resource_url}} | ||||||||||||||||||||||||||
|
Subroutine
protected_resource_url: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | sub authorize_params(%) | ||||||||||||||||||||||||||||
| 258 | 1 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
authorize_params: called CC=5 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 259 | 1 | my %params = (@{$self->{NOP_authorize_param}}, @_); | |||||||||||||||||||||||||||
| 260 | 1 | ▶ | $params{scope} ||= $self->scope; | ||||||||||||||||||||||||||
|
Condition33%1/3
$params{"scope"} ||= $self->scope
MC/DC0%0/2
$params{"scope"} ||= $self->scope
$params{"scope"}
$self->scope
Truth table33%1/3
A ||= B
A= $params{"scope"}B= $self->scope
| |||||||||||||||||||||||||||||
| 261 | 1 | ▶ | $params{state} ||= $self->state; | ||||||||||||||||||||||||||
|
Condition33%1/3
$params{"state"} ||= $self->state
MC/DC0%0/2
$params{"state"} ||= $self->state
$params{"state"}
$self->state
Truth table33%1/3
A ||= B
A= $params{"state"}B= $self->state
| |||||||||||||||||||||||||||||
| 262 | 1 | ▶ | $params{hd} ||= $self->hd; | ||||||||||||||||||||||||||
|
Condition33%1/3
$params{"hd"} ||= $self->hd
MC/DC0%0/2
$params{"hd"} ||= $self->hd
$params{"hd"}
$self->hd
Truth table33%1/3
A ||= B
A= $params{"hd"}B= $self->hd
| |||||||||||||||||||||||||||||
| 263 | 1 | ▶ | $params{client_id} ||= $self->id; | ||||||||||||||||||||||||||
|
Condition33%1/3
$params{"client_id"} ||= $self->id
MC/DC0%0/2
$params{"client_id"} ||= $self->id
$params{"client_id"}
$self->id
Truth table33%1/3
A ||= B
A= $params{"client_id"}B= $self->id
| |||||||||||||||||||||||||||||
| 264 | 1 | \%params; | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | sub access_token_params(%) | ||||||||||||||||||||||||||||
| 268 | 1 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
access_token_params: called CC=5 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 269 | 1 | my %params = (@{$self->{NOP_access_token_param}}, @_); | |||||||||||||||||||||||||||
| 270 | 1 | ▶ | $params{code} ||= ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$params{"code"} ||= ""
MC/DC0%0/1
$params{"code"} ||= ""
$params{"code"}
Truth table50%1/2
A
A= $params{"code"}
| |||||||||||||||||||||||||||||
| 271 | 1 | ▶ | $params{client_id} ||= $self->id; | ||||||||||||||||||||||||||
|
Condition33%1/3
$params{"client_id"} ||= $self->id
MC/DC0%0/2
$params{"client_id"} ||= $self->id
$params{"client_id"}
$self->id
Truth table33%1/3
A ||= B
A= $params{"client_id"}B= $self->id
| |||||||||||||||||||||||||||||
| 272 | 1 | ▶ | $params{client_secret} ||= $self->secret; | ||||||||||||||||||||||||||
|
Condition33%1/3
$params{"client_secret"} ||= $self->secret
MC/DC0%0/2
$params{"client_secret"} ||= $self->secret
$params{"client_secret"}
$self->secret
Truth table33%1/3
A ||= B
A= $params{"client_secret"}B= $self->secret
| |||||||||||||||||||||||||||||
| 273 | 1 | ▶ | $params{grant_type} ||= $self->grant_type; | ||||||||||||||||||||||||||
|
Condition33%1/3
$params{"grant_type"} ||= $self->grant_type
MC/DC0%0/2
$params{"grant_type"} ||= $self->grant_type
$params{"grant_type"}
$self->grant_type
Truth table33%1/3
A ||= B
A= $params{"grant_type"}B= $self->grant_type
| |||||||||||||||||||||||||||||
| 274 | 1 | \%params; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | sub refresh_token_params(%) | ||||||||||||||||||||||||||||
| 278 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
refresh_token_params: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 279 | 0 | my %params = (@{$self->{NOP_refresh_token_param}}, @_); | |||||||||||||||||||||||||||
| 280 | 0 | ▶ | $params{client_id} ||= $self->id; | ||||||||||||||||||||||||||
|
Condition0%0/3
$params{"client_id"} ||= $self->id
MC/DC0%0/2
$params{"client_id"} ||= $self->id
$params{"client_id"}
$self->id
Truth table0%0/3
A ||= B
A= $params{"client_id"}B= $self->id
| |||||||||||||||||||||||||||||
| 281 | 0 | ▶ | $params{client_secret} ||= $self->secret; | ||||||||||||||||||||||||||
|
Condition0%0/3
$params{"client_secret"} ||= $self->secret
MC/DC0%0/2
$params{"client_secret"} ||= $self->secret
$params{"client_secret"}
$self->secret
Truth table0%0/3
A ||= B
A= $params{"client_secret"}B= $self->secret
| |||||||||||||||||||||||||||||
| 282 | 0 | \%params; | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | sub protected_resource_params(%) | ||||||||||||||||||||||||||||
| 286 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
protected_resource_params: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 287 | 0 | my %params = (@{$self->{NOP_protected_resource_param}}, @_); | |||||||||||||||||||||||||||
| 288 | 0 | \%params; | |||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 4 | 1; | |||||||||||||||||||||||||||