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 |
- |
|
|