--- /dev/null
+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;