@@ -, +, @@ dependency - Makes the dependency optional - Makes the unit tests for the OAuth2 client credentials flow skip if the dependency is not met. --- C4/Installer/PerlDependencies.pm | 2 +- Koha/REST/V1/Auth.pm | 3 ++- Koha/REST/V1/OAuth.pm | 3 ++- t/db_dependent/api/v1/oauth.t | 13 ++++++++++++- 4 files changed, 17 insertions(+), 4 deletions(-) --- a/C4/Installer/PerlDependencies.pm +++ a/C4/Installer/PerlDependencies.pm @@ -890,7 +890,7 @@ our $PERL_DEPS = { }, 'Net::OAuth2::AuthorizationServer' => { usage => 'REST API', - required => '1', + required => '0', min_ver => '0.16', }, }; --- a/Koha/REST/V1/Auth.pm +++ a/Koha/REST/V1/Auth.pm @@ -120,7 +120,8 @@ sub authenticate_api_request { if ($authorization_header and $authorization_header =~ /^Bearer /) { # attempt to use OAuth2 authentication - if ( ! Module::Load::Conditional::can_load('Net::OAuth2::AuthorizationServer') ) { + if ( ! Module::Load::Conditional::can_load( + modules => {'Net::OAuth2::AuthorizationServer' => undef} )) { Koha::Exceptions::Authorization::Unauthorized->throw( error => 'Authentication failure.' ); --- a/Koha/REST/V1/OAuth.pm +++ a/Koha/REST/V1/OAuth.pm @@ -40,7 +40,8 @@ sub token { my $c = shift->openapi->valid_input or return; - if ( Module::Load::Conditional::can_load('Net::OAuth2::AuthorizationServer') ) { + if ( Module::Load::Conditional::can_load( + modules => {'Net::OAuth2::AuthorizationServer' => undef} )) { require Net::OAuth2::AuthorizationServer; } else { --- a/t/db_dependent/api/v1/oauth.t +++ a/t/db_dependent/api/v1/oauth.t @@ -17,10 +17,13 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More; use Test::MockModule; use Test::Mojo; +use Module::Load::Conditional qw(can_load); + +use Koha::ApiKeys; use Koha::Database; use Koha::Patrons; @@ -31,7 +34,15 @@ my $t = Test::Mojo->new('Koha::REST::V1'); my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new(); +if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) { + plan tests => 2; +} +else { + plan skip_all => 'Net::OAuth2::AuthorizationServer not available'; +} + subtest '/oauth/token tests' => sub { + plan tests => 27; $schema->storage->txn_begin; --