| 1 | package WWW::Suffit::Client::V1; | ||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | =encoding utf-8 | ||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | WWW::Suffit::Client::V1 - The Suffit API client library for V1 methods | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | use WWW::Suffit::Client::V1; | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | This library provides V1 methods for access to Suffit API servers | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | =head1 API METHODS | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | List of predefined the Suffit API methods | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | =head2 authn | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | my $status = $client->authn($username, $password, $address); | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | Performs user authentication on the OWL system | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | =head2 authz | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | my $status = $client->authz(GET => "https://bob@owl.localhost:8695/stuff"); | ||||||||||||||||||||||||||||||||
| 33 | my $status = $client->authz(GET => "https://owl.localhost:8695/stuff", | ||||||||||||||||||||||||||||||||
| 34 | { # Options | ||||||||||||||||||||||||||||||||
| 35 | verbose => \1, | ||||||||||||||||||||||||||||||||
| 36 | username => "bob", | ||||||||||||||||||||||||||||||||
| 37 | address => "127.0.0.1", | ||||||||||||||||||||||||||||||||
| 38 | headers => { # Headers | ||||||||||||||||||||||||||||||||
| 39 | Accept => "text/html,text/plain", | ||||||||||||||||||||||||||||||||
| 40 | Connection => "keep-alive", | ||||||||||||||||||||||||||||||||
| 41 | Host => "owl.localhost:8695", | ||||||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||||||
| 43 | }, | ||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | Performs user authorization on the OWL system | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | =head2 pubkey | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | my $status = $client->pubkey(); | ||||||||||||||||||||||||||||||||
| 51 | my $status = $client->pubkey(1); # Set public_key to object | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | Returns RSA public key of the token owner | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | L<Mojolicious>, L<WWW::Suffit> | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | =head1 TO DO | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | See C<TODO> file | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | L<Mojo::UserAgent>, L<WWW::Suffit::UserAgent> | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt> | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | Copyright (C) 1998-2026 D&D Corporation | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | =head1 LICENSE | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | This program is distributed under the terms of the Artistic License Version 2.0 | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | See the C<LICENSE> file or L<https://opensource.org/license/artistic-2-0> for details | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | use parent qw/ WWW::Suffit::Client /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | use WWW::Suffit::Const qw/ :MIME /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | use WWW::Suffit::RSA; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | ## SUFFIT API V1 METHODS | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub authn { | ||||||||||||||||||||||||||||||
|
Subroutine
authn: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 91 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 92 | 0 | my $username = shift; | |||||||||||||||||||||||||||||||
| 93 | 0 | my $password = shift; | |||||||||||||||||||||||||||||||
| 94 | 0 | my $address = shift; | |||||||||||||||||||||||||||||||
| 95 | 0 | my $encrypted = 0; | |||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if (length($self->public_key)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 98 | 0 | my $rsa = WWW::Suffit::RSA->new(public_key => $self->public_key); | |||||||||||||||||||||||||||||||
| 99 | 0 | $password = $rsa->encrypt($password); # Encrypt password | |||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($rsa->error) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 101 | 0 | $self->error($rsa->error); | |||||||||||||||||||||||||||||||
| 102 | 0 | $self->status(0); | |||||||||||||||||||||||||||||||
| 103 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | 0 | $encrypted = 1; | |||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 0 | my %data = (); | |||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $data{username} = $username if defined $username; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $data{password} = $password if defined $password; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $data{address} = $address if defined $address; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 112 | 0 | $data{encrypted} = \$encrypted, | |||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | # Request | ||||||||||||||||||||||||||||||||
| 115 | return $self->request(POST => $self->str2url("v1/authn"), | ||||||||||||||||||||||||||||||||
| 116 | { # Headers | ||||||||||||||||||||||||||||||||
| 117 | Accept => CONTENT_TYPE_JSON, # "*/*" | ||||||||||||||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||||||||||||||
| 119 | json => {%data}, | ||||||||||||||||||||||||||||||||
| 120 | ); | ||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub authz { | ||||||||||||||||||||||||||||||
|
Subroutine
authz: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | my $method = shift // ''; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | my $url = shift // ''; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my $options = shift || {}; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $options = {} unless ref($options) eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | 0 | my %data = (); | |||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $data{method} = $method if length($method); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $data{url} = $url if length($url); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | $data{username} = $options->{username} if exists $options->{username}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | $data{verbose} = $options->{verbose} if exists $options->{verbose}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $data{address} = $options->{address} if exists $options->{address}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 134 | 0 | my $headers = $options->{headers}; | |||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | $data{headers} = $headers if ref($headers) eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | # Request | ||||||||||||||||||||||||||||||||
| 138 | 0 | return $self->request(POST => $self->str2url("v1/authz"), | |||||||||||||||||||||||||||||||
| 139 | { # Headers | ||||||||||||||||||||||||||||||||
| 140 | Accept => CONTENT_TYPE_JSON, # "*/*" | ||||||||||||||||||||||||||||||||
| 141 | }, | ||||||||||||||||||||||||||||||||
| 142 | json => {%data}, | ||||||||||||||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub pubkey { | ||||||||||||||||||||||||||||||
|
Subroutine
pubkey: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 146 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | my $set = shift || 0; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | # Request | ||||||||||||||||||||||||||||||||
| 150 | 0 | my $status = $self->request(GET => $self->str2url("v1/publicKey"), | |||||||||||||||||||||||||||||||
| 151 | { # Headers | ||||||||||||||||||||||||||||||||
| 152 | Accept => CONTENT_TYPE_JSON, # "*/*" | ||||||||||||||||||||||||||||||||
| 153 | }, | ||||||||||||||||||||||||||||||||
| 154 | ); | ||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | return 0 unless $status; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | # Get public_key | ||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my $public_key = $self->res->json("/public_key") if $self->res->json("/status"); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | $self->public_key($public_key) if $set && length($public_key // ''); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$set and length($public_key // "")
$public_key // ""
MC/DC0%0/2
$set and length($public_key // "")
$set
$public_key
Truth table0%0/3
A and B
A= $setB= $public_key
| |||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | 0 | return $status; | |||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | 1 | 1; | |||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | __END__ | ||||||||||||||||||||||||||||||||