Client/ApiUserAgentBuilder.pm

filter: Statementstmt 100% 32 / 32 Branchbran n/a Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 94.0% 47 / 50 CC 2 SCAR 1.7
CC
2
Cov
97%
build_api_useragent_from_token_value
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Client/User.pm ↑ Summary Client/Trait/HashStore.pm »
1 package OIDC::Client::ApiUserAgentBuilder;
2  
3 8 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Mojo::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =encoding utf8
11  
12 =head1 NAME
13  
14 OIDC::Client::ApiUserAgentBuilder - API user agent builder
15  
16 =head1 DESCRIPTION
17  
18 Exports functions that help create an API user agent (L<Mojo::UserAgent> object).
19 For each request, the user agent includes the access token in the C<Authorization> header.
20  
21 =cut
22  
23 8 Readonly my $DEFAULT_TOKEN_TYPE => 'Bearer';
24  
25 8 Moose::Exporter->setup_import_methods(as_is => [qw/build_api_useragent_from_token_response
26 build_api_useragent_from_access_token
27 build_api_useragent_from_token_value
28 /]);
29  
30  
31 =head1 FUNCTIONS
32  
33 =head2 build_api_useragent_from_token_response( $token_response )
34  
35 Builds a L<Mojo::UserAgent> object from an L<OIDC::Client::TokenResponse> object.
36  
37 =cut
38  
39 3 ▶sub build_api_useragent_from_token_response {
Subroutine build_api_useragent_from_token_response: called CC=1 SCAR=0.0
Pod documented
40 3 my ($token_response) = pos_validated_list(\@_, { isa => 'OIDC::Client::TokenResponse', optional => 0 });
41  
42 3 return build_api_useragent_from_token_value($token_response->access_token,
43 $token_response->token_type);
44 }
45  
46  
47 =head2 build_api_useragent_from_access_token( $access_token )
48  
49 Builds a L<Mojo::UserAgent> object from an L<OIDC::Client::AccessToken> object.
50  
51 =cut
52  
53 6 ▶sub build_api_useragent_from_access_token {
Subroutine build_api_useragent_from_access_token: called CC=1 SCAR=0.0
Pod documented
54 6 my ($access_token) = pos_validated_list(\@_, { isa => 'OIDC::Client::AccessToken', optional => 0 });
55  
56 6 return build_api_useragent_from_token_value($access_token->token,
57 $access_token->token_type);
58 }
59  
60  
61 =head2 build_api_useragent_from_token_value( $token_value, $token_type )
62  
63 Builds a L<Mojo::UserAgent> object from a token value (string).
64  
65 =cut
66  
67 12 ▶sub build_api_useragent_from_token_value {
Subroutine build_api_useragent_from_token_value: called CC=2 SCAR=7.0
Pod documented
68 12 my ($token_value, $token_type) = pos_validated_list(\@_, { isa => 'Str', optional => 0 },
69 { isa => 'Maybe[Str]', optional => 1 });
70 12 ▶ $token_type ||= $DEFAULT_TOKEN_TYPE;
Condition66%2/3
$token_type ||= $DEFAULT_TOKEN_TYPE
l!l&&r!l&&!r
840
MC/DC0%0/2
$token_type ||= $DEFAULT_TOKEN_TYPE
$token_type $DEFAULT_TOKEN_TYPE
Truth table66%2/3
A ||= B
A= $token_typeB= $DEFAULT_TOKEN_TYPE
ABresult
1X1
011
000
71  
72 12 my $ua = Mojo::UserAgent->new();
73  
74 6 ▶ $ua->on(start => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
75 6 my ($ua, $tx) = @_;
76 6 $tx->req->headers->authorization("$token_type $token_value");
77 12 });
78  
79 12 return $ua;
80 }
81  
82 8 1;
« Client/User.pm ↑ Summary Client/Trait/HashStore.pm »