view release on metacpan or search on metacpan
lib/WWW/Suffit/Server/API/Admin.pm view on Meta::CPAN
"attributes": "",
"comment": "Test user for internal testing only",
"created": 1678741533,
"email": "test@owl.localhost",
"flags": 0,
"id": 3,
"name": "Test User",
"not_after": null,
"not_before": 1678741533,
"password": "9f86...0a08",
"private_key": "",
"public_key": "",
"role": "Test user",
"username": "test"
}
]
=head2 POST /api/admin/user
Adds user's data
lib/WWW/Suffit/Server/API/Admin.pm view on Meta::CPAN
-X POST -d '{
"username": "bob",
"name": "Bob",
"email": "bob@example.com",
"password": "bob",
"algorithm": "SHA256",
"role": "Test user",
"flags": 0,
"not_after": null,
"public_key": null,
"private_key": null,
"attributes": null,
"comment": "Test user for unit testing only"
}' \
https://owl.localhost:8695/api/admin/user
> POST /api/admin/user HTTP/1.1
> Host: owl.localhost:8695
> User-Agent: curl/7.68.0
> Accept: */*
> Authorization: OWL eyJh...j1rM
lib/WWW/Suffit/Server/API/Admin.pm view on Meta::CPAN
"attributes": "",
"comment": "Test user for unit testing only",
"created": 1683893750,
"email": "bob@example.com",
"flags": 0,
"id": 13,
"name": "Bob",
"not_after": 0,
"not_before": 1683893750,
"password": "81b6...8ce9",
"private_key": "-----BEGIN RSA PRIVATE KEY-----...",
"public_key": "-----BEGIN RSA PUBLIC KEY-----...",
"role": "Test user",
"status": true,
"username": "bob"
}
=head2 GET /api/admin/user/USERNAME
GET /api/admin/user/<USERNAME>
GET /api/admin/user/?username=<USERNAME>
lib/WWW/Suffit/Server/API/Admin.pm view on Meta::CPAN
"attributes": "",
"comment": "Test user for internal testing only",
"created": 1678741533,
"email": "test@owl.localhost",
"flags": 0,
"id": 3,
"name": "Test User",
"not_after": null,
"not_before": 1678741533,
"password": "9f86...0a08",
"private_key": "",
"public_key": "",
"role": "Test user",
"status": true,
"username": "test"
}
=head2 PUT /api/admin/user/USERNAME
Sets user's data
lib/WWW/Suffit/Server/API/Admin.pm view on Meta::CPAN
"id": 13,
"username": "bob",
"name": "Bob Bob",
"email": "bob@example.com",
"password": "bob",
"algorithm": "SHA256",
"role": "Test user",
"flags": 0,
"not_after": null,
"public_key": null,
"private_key": null,
"attributes": null,
"comment": "Test user for unit testing only"
}' \
https://owl.localhost:8695/api/admin/user/bob
> PUT /api/admin/user/bob HTTP/1.1
> Host: owl.localhost:8695
> User-Agent: curl/7.68.0
> Accept: */*
> Authorization: OWL eyJh...j1rM
lib/WWW/Suffit/Server/API/Admin.pm view on Meta::CPAN
"attributes": "",
"comment": "Test user for unit testing only",
"created": 1683893750,
"email": "bob@example.com",
"flags": 0,
"id": 13,
"name": "Bob Bob",
"not_after": 0,
"not_before": 1683894066,
"password": "81b6...8ce9",
"private_key": "-----BEGIN RSA PRIVATE KEY-----...",
"public_key": "-----BEGIN RSA PUBLIC KEY-----...",
"role": "Test user",
"status": true,
"username": "bob"
}
=head2 DELETE /api/admin/user/USERNAME
Delete user by username
lib/WWW/Suffit/Server/API/Admin.pm view on Meta::CPAN
my $flags = trim($self->req->json('/flags') || 0);
return $self->reply->json_error(400 => "E1209" => "Incorrect flags")
unless is_integer($flags);
$data{flags} = $flags;
# Get not_after
my $is_disabled = $self->req->json('/disabled') || 0;
$data{not_after} = $is_disabled ? time() : undef;
# Text fields
foreach my $k (qw/public_key private_key attributes comment/) {
my $v = $self->req->json("/$k") // '';
$data{$k} = $v;
}
# Gen RSA keys
unless (length($data{public_key}) || length($data{private_key})) {
my %ks = $self->gen_rsakeys();
return $self->reply->json_error(500 => "E1215" => $ks{error}) if $ks{error};
$data{$_} = $ks{$_} for qw/public_key private_key/;
}
# Set user data
$authdb->user_set(%data)
or return $self->reply->json_error($authdb->code, $authdb->error || "E1216: Can't set user data to authorization database");
# Get pure data from AuthDB
my %user_data = $authdb->user_get($username);
return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error;
lib/WWW/Suffit/Server/API/Auth.pm view on Meta::CPAN
# Token type
return $self->reply->json_error(400 => "E1020" => "Incorrect token type. Supported types: session, access, api")
unless grep {$token_type eq $_} (qw/session access api/);
# Please provide username and password for authorization
return $self->reply->json_error(401 => "E1021" => "No username specified") unless length($username);
return $self->reply->json_error(401 => "E1022" => "No password specified") unless length($password);
# Password decrypt
if ($encrypted && length($password)) {
my $rsa = WWW::Suffit::RSA->new(private_key => $self->app->private_key);
$password = $rsa->decrypt($password);
return $self->reply->json_error(500 => "E1023" => $rsa->error) if $rsa->error; # RSA decrypt error
}
# Authentication
$authdb->authn(
u => $username,
p => $password,
a => $ip, # For check by stats
k => $cachekey,
lib/WWW/Suffit/Server/API/User.pm view on Meta::CPAN
> Authorization: OWL eyJh...R_0c
>
< HTTP/1.1 200 OK
< Date: Fri, 12 May 2023 06:31:21 GMT
< Server: OWL/1.00
< Content-Type: application/json;charset=UTF-8
< Content-Length: 1228
<
{
"error": "",
"private_key": "-----BEGIN RSA PRIVATE KEY-----...",
"public_key": "-----BEGIN RSA PUBLIC KEY-----",
"status": true
}
=head2 PATCH /api/user/passwd
Change password for user
# curl -v -H "Authorization: OWL eyJh...Bh7g" \
-X PATCH -d '{
lib/WWW/Suffit/Server/API/V1.pm view on Meta::CPAN
sub authn {
my $self = shift;
my $username = $self->req->json('/username') // '';
my $password = $self->req->json('/password') // '';
my $address = $self->req->json('/address') // '';
my $encrypted = $self->req->json('/encrypted') || 0;
my $cachekey = $self->stash('cachekey');
my $authdb = $self->authdb;
my $acc_user = $authdb->cached_user($self->stash('username'), $cachekey);
my $public_key = $acc_user->public_key // '';
my $private_key = $acc_user->private_key // '';
$authdb->clean;
# Password decrypt
if ($encrypted && length($password)) {
return $self->reply->json_error(400 => "E1100" => "No RSA public key found") unless length $public_key;
return $self->reply->json_error(400 => "E1101" => "No RSA private key found") unless length $private_key;
my $rsa = WWW::Suffit::RSA->new->private_key($private_key);
$password = $rsa->decrypt($password); # RSA Decrypt password
return $self->reply->json_error(500 => "E1102" => $rsa->error || "RSA decrypt error") if $rsa->error;
}
# Authentication
return $self->reply->json_error(
$authdb->code, $authdb->error || "E1103: Incorrect username or password"
) unless $authdb->authn(
u => $username,
p => $password,