| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::Suffit::Client::V1; | 
| 2 | 1 |  |  | 1 |  | 69040 | use warnings; | 
|  | 1 |  |  |  |  | 11 |  | 
|  | 1 |  |  |  |  | 33 |  | 
| 3 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 33 |  | 
| 4 | 1 |  |  | 1 |  | 589 | use utf8; | 
|  | 1 |  |  |  |  | 15 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 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 VERSION | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | Version 1.01 | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | use WWW::Suffit::Client::V1; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | This library provides V1 methods for access to Suffit API servers | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =head1 API METHODS | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | List of predefined the Suffit API methods | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | =head2 authn | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | my $status = $client->authn($username, $password); | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | Performs user authentication on the OWL system | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =head2 authz | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | my $status = $client->authz(GET => "https://bob@owl.localhost:8695/stuff"); | 
| 37 |  |  |  |  |  |  | my $status = $client->authz(GET => "https://owl.localhost:8695/stuff", | 
| 38 |  |  |  |  |  |  | { # Options | 
| 39 |  |  |  |  |  |  | verbose => \1, | 
| 40 |  |  |  |  |  |  | username => "bob", | 
| 41 |  |  |  |  |  |  | address => "127.0.0.1", | 
| 42 |  |  |  |  |  |  | headers => { # Headers | 
| 43 |  |  |  |  |  |  | Accept => "text/html,text/plain", | 
| 44 |  |  |  |  |  |  | Connection => "keep-alive", | 
| 45 |  |  |  |  |  |  | Host => "owl.localhost:8695", | 
| 46 |  |  |  |  |  |  | }, | 
| 47 |  |  |  |  |  |  | }, | 
| 48 |  |  |  |  |  |  | ); | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | Performs user authorization on the OWL system | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =head2 pubkey | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | my $status = $client->pubkey(); | 
| 55 |  |  |  |  |  |  | my $status = $client->pubkey(1); # Set public_key to object | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | Returns RSA public key of the token owner | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =head1 DEPENDENCIES | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | L, L | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =head1 TO DO | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | See C file | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | L, L | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =head1 AUTHOR | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | Serż Minus (Sergey Lepenkov) L Eabalama@cpan.orgE | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | Copyright (C) 1998-2023 D&D Corporation. All Rights Reserved | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =head1 LICENSE | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or | 
| 82 |  |  |  |  |  |  | modify it under the same terms as Perl itself. | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | See C file and L | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | =cut | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | our $VERSION = '1.01'; | 
| 89 |  |  |  |  |  |  |  | 
| 90 | 1 |  |  | 1 |  | 486 | use parent qw/ WWW::Suffit::Client /; | 
|  | 1 |  |  |  |  | 307 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 91 |  |  |  |  |  |  |  | 
| 92 | 1 |  |  | 1 |  | 68 | use WWW::Suffit::Const qw/ :MIME /; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 92 |  | 
| 93 | 1 |  |  | 1 |  | 548 | use WWW::Suffit::RSA; | 
|  | 1 |  |  |  |  | 5124 |  | 
|  | 1 |  |  |  |  | 15 |  | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | ## SUFFIT API V1 METHODS | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | sub authn { | 
| 98 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 99 | 0 |  |  |  |  |  | my $username = shift; | 
| 100 | 0 |  |  |  |  |  | my $password = shift; | 
| 101 | 0 |  |  |  |  |  | my $encrypted = 0; | 
| 102 |  |  |  |  |  |  |  | 
| 103 | 0 | 0 |  |  |  |  | if (length($self->public_key)) { | 
| 104 | 0 |  |  |  |  |  | my $rsa = WWW::Suffit::RSA->new(public_key => $self->public_key); | 
| 105 | 0 |  |  |  |  |  | $password = $rsa->encrypt($password); # Encrypt password | 
| 106 | 0 | 0 |  |  |  |  | if ($rsa->error) { | 
| 107 | 0 |  |  |  |  |  | $self->error($rsa->error); | 
| 108 | 0 |  |  |  |  |  | $self->status(0); | 
| 109 | 0 |  |  |  |  |  | return 0; | 
| 110 |  |  |  |  |  |  | } | 
| 111 | 0 |  |  |  |  |  | $encrypted = 1; | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 0 |  |  |  |  |  | my %data = (); | 
| 115 | 0 | 0 |  |  |  |  | $data{username} = $username if defined $username; | 
| 116 | 0 | 0 |  |  |  |  | $data{password} = $password if defined $password; | 
| 117 | 0 |  |  |  |  |  | $data{encrypted} = \$encrypted, | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | # Request | 
| 120 |  |  |  |  |  |  | return $self->request(POST => $self->str2url("v1/authn"), | 
| 121 |  |  |  |  |  |  | { # Headers | 
| 122 |  |  |  |  |  |  | Accept => CONTENT_TYPE_JSON, # "*/*" | 
| 123 |  |  |  |  |  |  | }, | 
| 124 |  |  |  |  |  |  | json => {%data}, | 
| 125 |  |  |  |  |  |  | ); | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  | sub authz { | 
| 128 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 129 | 0 |  | 0 |  |  |  | my $method = shift // ''; | 
| 130 | 0 |  | 0 |  |  |  | my $url = shift // ''; | 
| 131 | 0 |  | 0 |  |  |  | my $options = shift || {}; | 
| 132 | 0 | 0 |  |  |  |  | $options = {} unless ref($options) eq 'HASH'; | 
| 133 | 0 |  |  |  |  |  | my %data = (); | 
| 134 | 0 | 0 |  |  |  |  | $data{method} = $method if length($method); | 
| 135 | 0 | 0 |  |  |  |  | $data{url} = $url if length($url); | 
| 136 | 0 | 0 |  |  |  |  | $data{username} = $options->{username} if exists $options->{username}; | 
| 137 | 0 | 0 |  |  |  |  | $data{verbose} = $options->{verbose} if exists $options->{verbose}; | 
| 138 | 0 | 0 |  |  |  |  | $data{address} = $options->{address} if exists $options->{address}; | 
| 139 | 0 |  |  |  |  |  | my $headers = $options->{headers}; | 
| 140 | 0 | 0 |  |  |  |  | $data{headers} = $headers if ref($headers) eq 'HASH'; | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | # Request | 
| 143 | 0 |  |  |  |  |  | return $self->request(POST => $self->str2url("v1/authz"), | 
| 144 |  |  |  |  |  |  | { # Headers | 
| 145 |  |  |  |  |  |  | Accept => CONTENT_TYPE_JSON, # "*/*" | 
| 146 |  |  |  |  |  |  | }, | 
| 147 |  |  |  |  |  |  | json => {%data}, | 
| 148 |  |  |  |  |  |  | ); | 
| 149 |  |  |  |  |  |  | } | 
| 150 |  |  |  |  |  |  | sub pubkey { | 
| 151 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 152 | 0 |  | 0 |  |  |  | my $set = shift || 0; | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | # Request | 
| 155 | 0 |  |  |  |  |  | my $status = $self->request(GET => $self->str2url("v1/publicKey"), | 
| 156 |  |  |  |  |  |  | { # Headers | 
| 157 |  |  |  |  |  |  | Accept => CONTENT_TYPE_JSON, # "*/*" | 
| 158 |  |  |  |  |  |  | }, | 
| 159 |  |  |  |  |  |  | ); | 
| 160 | 0 | 0 |  |  |  |  | return 0 unless $status; | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | # Get public_key | 
| 163 | 0 | 0 |  |  |  |  | my $public_key = $self->res->json("/public_key") if $self->res->json("/status"); | 
| 164 | 0 | 0 | 0 |  |  |  | $self->public_key($public_key) if $set && length($public_key // ''); | 
|  |  |  | 0 |  |  |  |  | 
| 165 |  |  |  |  |  |  |  | 
| 166 | 0 |  |  |  |  |  | return $status; | 
| 167 |  |  |  |  |  |  | } | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | 1; | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | __END__ |