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