Bug 16892: Add automatic patron registration via OAuth2 login

10988 added the ability to log into the OPAC authenticating with
Google Open ID Connect. This extends it, by allowing an
unregistered patron to have an account automatically created
with default category code and branch.

This is accomplished by adding 3 system preferences.
- GoogleOpenIDConnectAutoRegister
      whether it will attempt to auto-register the patron.
- GoogleOpenIDConnectDefaultCategory
      This category code will be used to create Google OpenID Connect patrons.
- GoogleOpenIDConnectDefaultBranch'
      This branch code will be used to create Google OpenID Connect patrons.

Sponsored-by: Tulong Aklatan

Signed-off-by: Eugene Jose Espinoza <eugenegf@yahoo.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Mark Tompsett 2016-07-11 00:42:40 -04:00 committed by Jonathan Druart
parent a4237785d9
commit ae45243fae
3 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,4 @@
INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
('GoogleOpenIDConnectAutoRegister', '0',NULL,' Google OpenID Connect logins to auto-register patrons.','YesNo'),
('GoogleOpenIDConnectDefaultCategory','','','This category code will be used to create Google OpenID Connect patrons.','Textarea'),
('GoogleOpenIDConnectDefaultBranch', '','','This branch code will be used to create Google OpenID Connect patrons.','Textarea');

View file

@ -156,6 +156,18 @@ Administration:
- "Google OpenID Connect Restrict to domain (or subdomain of this domain): "
- pref: GoogleOpenIDConnectDomain
- Leave blank for all google domains
-
- pref: GoogleOpenIDConnectAutoRegister
choices:
yes: Allow
no: "Don't Allow"
- users logging in with Google Open ID to automatically register.
-
- pref: GoogleOpenIDConnectDefaultCategory
- Use this category code when automatically registering a Google Open ID patron.
-
- pref: GoogleOpenIDConnectDefaultBranch
- Use this branch code when automatically registering a Google Open ID patron.
Share anonymous usage statistics:
-
- "Share anonymous Koha usage data with the Koha community: "

View file

@ -34,7 +34,9 @@ use Modern::Perl;
use CGI qw ( -utf8 escape );
use C4::Auth qw{ checkauth get_session get_template_and_user };
use C4::Context;
use C4::Members;
use C4::Output;
use Koha::Patrons;
use LWP::UserAgent;
use HTTP::Request::Common qw{ POST };
@ -179,6 +181,29 @@ elsif ( defined $query->param('code') ) {
. ' .' );
}
else {
my $auto_registration = C4::Context->preference('GoogleOpenIDConnectAutoRegister') // q{0};
my $borrower = Koha::Patrons->find( { email => $email } );
if (! $borrower && $auto_registration==1) {
my $cardnumber = fixup_cardnumber();
my $firstname = $claims_json->{'given_name'} // q{};
my $surname = $claims_json->{'family_name'} // q{};
my $delimiter = $firstname ? q{.} : q{};
my $userid = $firstname . $delimiter . $surname;
my $categorycode = C4::Context->preference('GoogleOpenIDConnectDefaultCategory') // q{};
my $branchcode = C4::Context->preference('GoogleOpenIDConnectDefaultBranch') // q{};
my $password = undef;
$borrower = Koha::Patron->new( {
cardnumber => $cardnumber,
firstname => $firstname,
surname => $surname,
email => $email,
categorycode => $categorycode,
branchcode => $branchcode,
userid => $userid,
password => $password,
} );
$borrower->store();
}
my ( $userid, $cookie, $session_id ) =
checkauth( $query, 1, {}, 'opac', $email );
if ($userid) { # A user with this email is registered in koha