Lines 19-25
use Modern::Perl;
Link Here
|
19 |
|
19 |
|
20 |
use Mojo::Base 'Mojolicious::Controller'; |
20 |
use Mojo::Base 'Mojolicious::Controller'; |
21 |
use Mojo::JSON; |
21 |
use Mojo::JSON; |
22 |
use Mojo::JWT; |
|
|
23 |
use Digest::MD5 qw( md5_base64 ); |
22 |
use Digest::MD5 qw( md5_base64 ); |
24 |
use Encode; |
23 |
use Encode; |
25 |
|
24 |
|
Lines 28-33
use C4::Context;
Link Here
|
28 |
use C4::Circulation qw( AddIssue AddRenewal CanBookBeRenewed ); |
27 |
use C4::Circulation qw( AddIssue AddRenewal CanBookBeRenewed ); |
29 |
use Koha::Checkouts; |
28 |
use Koha::Checkouts; |
30 |
use Koha::Old::Checkouts; |
29 |
use Koha::Old::Checkouts; |
|
|
30 |
use Koha::Token; |
31 |
|
31 |
|
32 |
use Try::Tiny qw( catch try ); |
32 |
use Try::Tiny qw( catch try ); |
33 |
|
33 |
|
Lines 123-135
sub get_availability {
Link Here
|
123 |
C4::Circulation::CanBookBeIssued( $patron, undef, undef, $inprocess, $ignore_reserves, |
123 |
C4::Circulation::CanBookBeIssued( $patron, undef, undef, $inprocess, $ignore_reserves, |
124 |
$params ); |
124 |
$params ); |
125 |
|
125 |
|
126 |
my $token; |
126 |
my $confirm_keys = join( /:/, sort keys %{$confirmation} ); |
127 |
if (keys %{$confirmation}) { |
127 |
my $tokenizer = Koha::Token->new; |
128 |
my $claims = { map { $_ => 1 } keys %{$confirmation} }; |
128 |
my $token = $tokeniser->generate_jwt({ id => $confirm_keys }); |
129 |
my $secret = |
|
|
130 |
md5_base64( Encode::encode( 'UTF-8', C4::Context->config('pass') ) ); |
131 |
$token = Mojo::JWT->new( claims => $claims, secret => $secret )->encode; |
132 |
} |
133 |
|
129 |
|
134 |
my $response = { |
130 |
my $response = { |
135 |
blockers => $impossible, |
131 |
blockers => $impossible, |
Lines 210-232
sub add {
Link Here
|
210 |
# Check for existance of confirmation token |
206 |
# Check for existance of confirmation token |
211 |
# and if exists check validity |
207 |
# and if exists check validity |
212 |
if ( my $token = $c->validation->param('confirmation') ) { |
208 |
if ( my $token = $c->validation->param('confirmation') ) { |
213 |
my $secret = |
209 |
my $confirm_keys = join( /:/, sort keys %{$confirmation} ); |
214 |
md5_base64( |
210 |
my $tokenizer = Koha::Token->new; |
215 |
Encode::encode( 'UTF-8', C4::Context->config('pass') ) ); |
211 |
$confirmed = $tokenizer->check_jwt( |
216 |
my $claims = try { |
212 |
{ id => $confirm_keys, token => $token } ); |
217 |
Mojo::JWT->new( secret => $secret )->decode($token); |
|
|
218 |
} |
219 |
catch { |
220 |
return $c->render( |
221 |
status => 403, |
222 |
openapi => { error => "Confirmation required" } |
223 |
); |
224 |
}; |
225 |
|
226 |
# check claims match |
227 |
my $token_claims = join( / /, sort keys %{$claims} ); |
228 |
my $confirm_keys = join( / /, sort keys %{$confirmation} ); |
229 |
$confirmed = 1 if ( $token_claims eq $confirm_keys ); |
230 |
} |
213 |
} |
231 |
|
214 |
|
232 |
unless ($confirmed) { |
215 |
unless ($confirmed) { |
233 |
- |
|
|