Lines 223-264
sub authenticate_api_request {
Link Here
|
223 |
my ($status, $session) = check_cookie_auth( |
223 |
my ($status, $session) = check_cookie_auth( |
224 |
$cookie, undef, |
224 |
$cookie, undef, |
225 |
{ remote_addr => $remote_addr }); |
225 |
{ remote_addr => $remote_addr }); |
226 |
if ($status eq "ok") { |
226 |
|
227 |
$user = Koha::Patrons->find( $session->param('number') ); |
227 |
if ( $c->req->url->to_abs->path eq '/api/v1/auth/otp/token_delivery' ) { |
228 |
$cookie_auth = 1; |
228 |
if ( $status eq 'additional-auth-needed' ) { |
229 |
} |
229 |
$user = Koha::Patrons->find( $session->param('number') ); |
230 |
elsif ($status eq "anon") { |
230 |
$cookie_auth = 1; |
231 |
$cookie_auth = 1; |
231 |
} |
232 |
} |
232 |
elsif ( $status eq 'ok' ) { |
233 |
elsif ($status eq "additional-auth-needed") { |
233 |
Koha::Exceptions::Authentication->throw( |
234 |
if ( $c->req->url->to_abs->path eq '/api/v1/auth/otp/token_delivery' ) { |
234 |
error => 'Cannot request a new token.' ); |
|
|
235 |
} |
236 |
else { |
237 |
Koha::Exceptions::Authentication::Required->throw( |
238 |
error => 'Authentication failure.' ); |
239 |
} |
240 |
} else { |
241 |
if ($status eq "ok") { |
235 |
$user = Koha::Patrons->find( $session->param('number') ); |
242 |
$user = Koha::Patrons->find( $session->param('number') ); |
236 |
$cookie_auth = 1; |
243 |
$cookie_auth = 1; |
237 |
} else { |
244 |
} |
|
|
245 |
elsif ($status eq "anon") { |
246 |
$cookie_auth = 1; |
247 |
} |
248 |
elsif ($status eq "additional-auth-needed") { |
249 |
} |
250 |
elsif ($status eq "maintenance") { |
251 |
Koha::Exceptions::UnderMaintenance->throw( |
252 |
error => 'System is under maintenance.' |
253 |
); |
254 |
} |
255 |
elsif ($status eq "expired" and $authorization) { |
256 |
Koha::Exceptions::Authentication::SessionExpired->throw( |
257 |
error => 'Session has been expired.' |
258 |
); |
259 |
} |
260 |
elsif ($status eq "failed" and $authorization) { |
238 |
Koha::Exceptions::Authentication::Required->throw( |
261 |
Koha::Exceptions::Authentication::Required->throw( |
239 |
error => 'Authentication failure.' |
262 |
error => 'Authentication failure.' |
240 |
); |
263 |
); |
241 |
} |
264 |
} |
242 |
} |
265 |
elsif ($authorization) { |
243 |
elsif ($status eq "maintenance") { |
266 |
Koha::Exceptions::Authentication->throw( |
244 |
Koha::Exceptions::UnderMaintenance->throw( |
267 |
error => 'Unexpected authentication status.' |
245 |
error => 'System is under maintenance.' |
268 |
); |
246 |
); |
269 |
} |
247 |
} |
|
|
248 |
elsif ($status eq "expired" and $authorization) { |
249 |
Koha::Exceptions::Authentication::SessionExpired->throw( |
250 |
error => 'Session has been expired.' |
251 |
); |
252 |
} |
253 |
elsif ($status eq "failed" and $authorization) { |
254 |
Koha::Exceptions::Authentication::Required->throw( |
255 |
error => 'Authentication failure.' |
256 |
); |
257 |
} |
258 |
elsif ($authorization) { |
259 |
Koha::Exceptions::Authentication->throw( |
260 |
error => 'Unexpected authentication status.' |
261 |
); |
262 |
} |
270 |
} |
263 |
} |
271 |
} |
264 |
|
272 |
|