View | Details | Raw Unified | Return to bug 22132
Collapse All | Expand All

(-)a/Koha/REST/V1/Auth.pm (-2 / +38 lines)
Lines 21-27 use Modern::Perl; Link Here
21
21
22
use Mojo::Base 'Mojolicious::Controller';
22
use Mojo::Base 'Mojolicious::Controller';
23
23
24
use C4::Auth qw( check_cookie_auth get_session haspermission );
24
use C4::Auth qw( check_cookie_auth checkpw_internal get_session haspermission );
25
use C4::Context;
25
use C4::Context;
26
26
27
use Koha::ApiKeys;
27
use Koha::ApiKeys;
Lines 37-42 use Koha::Exceptions; Link Here
37
use Koha::Exceptions::Authentication;
37
use Koha::Exceptions::Authentication;
38
use Koha::Exceptions::Authorization;
38
use Koha::Exceptions::Authorization;
39
39
40
use MIME::Base64;
40
use Module::Load::Conditional;
41
use Module::Load::Conditional;
41
use Scalar::Util qw( blessed );
42
use Scalar::Util qw( blessed );
42
use Try::Tiny;
43
use Try::Tiny;
Lines 151-156 sub authenticate_api_request { Link Here
151
            );
152
            );
152
        }
153
        }
153
    }
154
    }
155
    elsif ($authorization_header and $authorization_header =~ /^Basic / ) {
156
        $user = $c->_basic_auth( $authorization_header );
157
        unless ( $user ) {
158
            # If we have "Authorization: Basic" header and authentication
159
            # failed, do not try other authentication means
160
            Koha::Exceptions::Authentication::Required->throw(
161
                error => 'Authentication failure.'
162
            );
163
        }
164
    }
154
    else {
165
    else {
155
166
156
        my $cookie = $c->cookie('CGISESSID');
167
        my $cookie = $c->cookie('CGISESSID');
Lines 390-393 sub _object_ownership_by_reserve_id { Link Here
390
    return $reserve && $user->borrowernumber == $reserve->borrowernumber;
401
    return $reserve && $user->borrowernumber == $reserve->borrowernumber;
391
}
402
}
392
403
404
=head3 _basic_auth
405
406
Internal method that performs Basic authentication.
407
408
=cut
409
410
sub _basic_auth {
411
    my ( $c, $authorization_header ) = @_;
412
413
    my ( $type, $credentials ) = split / /, $authorization_header;
414
415
    unless ($credentials) {
416
        Koha::Exceptions::Authentication::Required->throw( error => 'Authentication failure.' );
417
    }
418
419
    my $decoded_credentials = decode_base64( $credentials );
420
    my ( $user_id, $password ) = split( /:/, $decoded_credentials, 2 );
421
422
    my $dbh = C4::Context->dbh;
423
    unless ( checkpw_internal($dbh, $user_id, $password ) ) {
424
        Koha::Exceptions::Authorization::Unauthorized->throw("Invalid password");
425
    }
426
427
    return Koha::Patrons->find({ userid => $user_id });
428
}
429
393
1;
430
1;
394
- 

Return to bug 22132