Bugzilla – Attachment 74383 Details for
Bug 20402
OAuth2 client credentials grant for REST API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20402: Remove dependency on Mojo::Plugin::OAuth2::Server
Bug-20402-Remove-dependency-on-MojoPluginOAuth2Ser.patch (text/plain), 2.84 KB, created by
Tomás Cohen Arazi (tcohen)
on 2018-04-17 19:35:18 UTC
(
hide
)
Description:
Bug 20402: Remove dependency on Mojo::Plugin::OAuth2::Server
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2018-04-17 19:35:18 UTC
Size:
2.84 KB
patch
obsolete
>From d2db3c0a8594d66910e5d26b8309bb4928a35fb3 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Tue, 17 Apr 2018 19:07:01 +0200 >Subject: [PATCH] Bug 20402: Remove dependency on Mojo::Plugin::OAuth2::Server > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > C4/Installer/PerlDependencies.pm | 5 ----- > Koha/REST/V1.pm | 3 --- > Koha/REST/V1/Auth.pm | 13 +++++++++++-- > 3 files changed, 11 insertions(+), 10 deletions(-) > >diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm >index 84a02b4940..fd1e3d63aa 100644 >--- a/C4/Installer/PerlDependencies.pm >+++ b/C4/Installer/PerlDependencies.pm >@@ -893,11 +893,6 @@ our $PERL_DEPS = { > required => '1', > min_ver => '0.16', > }, >- 'Mojolicious::Plugin::OAuth2::Server' => { >- usage => 'REST API', >- required => '1', >- min_ver => '0.40', >- } > }; > > 1; >diff --git a/Koha/REST/V1.pm b/Koha/REST/V1.pm >index 9059ea5069..57ad113291 100644 >--- a/Koha/REST/V1.pm >+++ b/Koha/REST/V1.pm >@@ -19,8 +19,6 @@ use Modern::Perl; > > use Mojo::Base 'Mojolicious'; > >-use Koha::OAuth; >- > use C4::Context; > > =head1 NAME >@@ -53,7 +51,6 @@ sub startup { > $self->secrets([$secret_passphrase]); > } > >- $self->plugin('OAuth2::Server' => Koha::OAuth::config); > $self->plugin(OpenAPI => { > url => $self->home->rel_file("api/v1/swagger/swagger.json"), > route => $self->routes->under('/api/v1')->to('Auth#under'), >diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm >index f9b885f491..65f0e719c9 100644 >--- a/Koha/REST/V1/Auth.pm >+++ b/Koha/REST/V1/Auth.pm >@@ -21,6 +21,8 @@ use Modern::Perl; > > use Mojo::Base 'Mojolicious::Controller'; > >+use Net::OAuth2::AuthorizationServer; >+ > use C4::Auth qw( check_cookie_auth get_session haspermission ); > use C4::Context; > >@@ -115,10 +117,17 @@ sub authenticate_api_request { > > my $authorization_header = $c->req->headers->authorization; > if ($authorization_header and $authorization_header =~ /^Bearer /) { >- if (my $oauth = $c->oauth) { >+ my $server = Net::OAuth2::AuthorizationServer->new; >+ my $grant = $server->client_credentials_grant(Koha::OAuth::config); >+ my ($type, $token) = split / /, $authorization_header; >+ my ($valid_token, $error) = $grant->verify_access_token( >+ access_token => $token, >+ ); >+ >+ if ($valid_token) { > my $clients = C4::Context->config('api_client'); > $clients = [ $clients ] unless ref $clients eq 'ARRAY'; >- my ($client) = grep { $_->{client_id} eq $oauth->{client_id} } @$clients; >+ my ($client) = grep { $_->{client_id} eq $valid_token->{client_id} } @$clients; > > my $patron = Koha::Patrons->find($client->{patron_id}); > my $permissions = $authorization->{'permissions'}; >-- >2.17.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20402
:
72865
|
72874
|
72886
|
72887
|
72888
|
72892
|
72893
|
72894
|
73086
|
73087
|
74009
|
74018
|
74050
|
74051
|
74069
|
74070
|
74088
|
74365
|
74366
|
74367
|
74368
|
74369
|
74380
|
74381
|
74382
|
74383
|
74384
|
74385
|
74386
|
74600
|
75026
|
75027
|
75028
|
75029
|
75030
|
75031
|
75032
|
75033
|
75189