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

(-)a/C4/Installer/PerlDependencies.pm (-5 lines)
Lines 893-903 our $PERL_DEPS = { Link Here
893
        required => '1',
893
        required => '1',
894
        min_ver  => '0.16',
894
        min_ver  => '0.16',
895
    },
895
    },
896
    'Mojolicious::Plugin::OAuth2::Server' => {
897
        usage    => 'REST API',
898
        required => '1',
899
        min_ver  => '0.40',
900
    }
901
};
896
};
902
897
903
1;
898
1;
(-)a/Koha/REST/V1.pm (-3 lines)
Lines 19-26 use Modern::Perl; Link Here
19
19
20
use Mojo::Base 'Mojolicious';
20
use Mojo::Base 'Mojolicious';
21
21
22
use Koha::OAuth;
23
24
use C4::Context;
22
use C4::Context;
25
23
26
=head1 NAME
24
=head1 NAME
Lines 53-59 sub startup { Link Here
53
        $self->secrets([$secret_passphrase]);
51
        $self->secrets([$secret_passphrase]);
54
    }
52
    }
55
53
56
    $self->plugin('OAuth2::Server' => Koha::OAuth::config);
57
    $self->plugin(OpenAPI => {
54
    $self->plugin(OpenAPI => {
58
        url => $self->home->rel_file("api/v1/swagger/swagger.json"),
55
        url => $self->home->rel_file("api/v1/swagger/swagger.json"),
59
        route => $self->routes->under('/api/v1')->to('Auth#under'),
56
        route => $self->routes->under('/api/v1')->to('Auth#under'),
(-)a/Koha/REST/V1/Auth.pm (-3 / +11 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use Mojo::Base 'Mojolicious::Controller';
22
use Mojo::Base 'Mojolicious::Controller';
23
23
24
use Net::OAuth2::AuthorizationServer;
25
24
use C4::Auth qw( check_cookie_auth get_session haspermission );
26
use C4::Auth qw( check_cookie_auth get_session haspermission );
25
use C4::Context;
27
use C4::Context;
26
28
Lines 115-124 sub authenticate_api_request { Link Here
115
117
116
    my $authorization_header = $c->req->headers->authorization;
118
    my $authorization_header = $c->req->headers->authorization;
117
    if ($authorization_header and $authorization_header =~ /^Bearer /) {
119
    if ($authorization_header and $authorization_header =~ /^Bearer /) {
118
        if (my $oauth = $c->oauth) {
120
        my $server = Net::OAuth2::AuthorizationServer->new;
121
        my $grant = $server->client_credentials_grant(Koha::OAuth::config);
122
        my ($type, $token) = split / /, $authorization_header;
123
        my ($valid_token, $error) = $grant->verify_access_token(
124
            access_token => $token,
125
        );
126
127
        if ($valid_token) {
119
            my $clients = C4::Context->config('api_client');
128
            my $clients = C4::Context->config('api_client');
120
            $clients = [ $clients ] unless ref $clients eq 'ARRAY';
129
            $clients = [ $clients ] unless ref $clients eq 'ARRAY';
121
            my ($client) = grep { $_->{client_id} eq $oauth->{client_id} } @$clients;
130
            my ($client) = grep { $_->{client_id} eq $valid_token->{client_id} } @$clients;
122
131
123
            my $patron = Koha::Patrons->find($client->{patron_id});
132
            my $patron = Koha::Patrons->find($client->{patron_id});
124
            my $permissions = $authorization->{'permissions'};
133
            my $permissions = $authorization->{'permissions'};
125
- 

Return to bug 20402