From 50066e466c2a78911e522c74e767011494129194 Mon Sep 17 00:00:00 2001 From: Jeff Godin Date: Tue, 28 May 2013 13:56:41 -0400 Subject: [PATCH] Implement LibraryREST auth method Initial LibraryREST implementation for Evergreen. Use this with the experimental code here: https://github.com/tadl/library-rest-api Signed-off-by: Jeff Godin --- Open-ILS/src/perlmods/MANIFEST | 1 + Open-ILS/src/perlmods/lib/OpenILS/LibraryREST.pm | 73 ++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 Open-ILS/src/perlmods/lib/OpenILS/LibraryREST.pm diff --git a/Open-ILS/src/perlmods/MANIFEST b/Open-ILS/src/perlmods/MANIFEST index 9f30b977ec..bbf20de361 100644 --- a/Open-ILS/src/perlmods/MANIFEST +++ b/Open-ILS/src/perlmods/MANIFEST @@ -115,6 +115,7 @@ lib/OpenILS/Application/Trigger/Validator/Acq/UserRequestReceived.pm lib/OpenILS/Application/Vandelay.pm lib/OpenILS/Const.pm lib/OpenILS/Event.pm +lib/OpenILS/LibraryREST.pm lib/OpenILS/Perm.pm lib/OpenILS/Reporter/Proxy.pm lib/OpenILS/Reporter/SQLBuilder.pm diff --git a/Open-ILS/src/perlmods/lib/OpenILS/LibraryREST.pm b/Open-ILS/src/perlmods/lib/OpenILS/LibraryREST.pm new file mode 100644 index 0000000000..9d1d10e641 --- /dev/null +++ b/Open-ILS/src/perlmods/lib/OpenILS/LibraryREST.pm @@ -0,0 +1,73 @@ +package OpenILS::LibraryREST; + +use strict; +use warnings; + +use OpenSRF::System; +use OpenSRF::AppSession; +use OpenILS::Utils::Fieldmapper; +use OpenSRF::Utils::SettingsClient; +use OpenILS::Application::AppUtils; +use OpenSRF::Utils qw/:datetime/; +use DateTime::Format::ISO8601; +my $U = 'OpenILS::Application::AppUtils'; + +use Digest::MD5 qw(md5_hex); + +my $bsconfig = '/openils/conf/opensrf_core.xml'; + +sub new { + my $class = shift; + my $type = ref($class) || $class; + my $self = {}; + + OpenSRF::System->bootstrap_client(config_file => $bsconfig); + + $self->{osrf_config} = OpenSRF::Utils::SettingsClient->new; + + Fieldmapper->import($self->{osrf_config}->config_value('IDL')); + + return bless $self, $type; +} + +sub get_auth { + my $self = shift; + my $user = shift; + my $pass = shift; + + my $seed = $U->simplereq( + 'open-ils.auth', + 'open-ils.auth.authenticate.init', $user ); + + my $response = $U->simplereq( + 'open-ils.auth', + 'open-ils.auth.authenticate.complete', + { + username => $user, + password => md5_hex($seed . md5_hex($pass)), + type => 'opac', + } + ); + + if( my $code = $U->event_code($response) ) { + my $txt = $response->{textcode}; + return { error => $txt}; + } + + my $token = $response->{payload}->{authtoken}; + + my $session = $U->simplereq( + 'open-ils.auth', + 'open-ils.auth.session.retrieve', + $token + ); + + return { + user => $session->id(), + token => $response->{payload}->{authtoken}, + }; + + return 0; +} + +1; -- 2.11.0