We should have 1 function that sets up the basics of a $session object which we can use across all our different authentication options.
Created attachment 136566 [details] [review] Bug 31050: C4::Context->setup_session() standardizes user session setup Test plan: 0. Apply patch and koha-plack --restart kohadev 1. Log into http://localhost:8081/cgi-bin/koha/mainpage.pl using "koha" user 2. Note the login is successful 3. koha-mysql kohadev 3a. select * from sessions; Session in MySQL sets parameters like surname, flags, interface, ip, lasttime, etc 3b. select * from systempreferences where variable = 'Version'; 3c. update systempreferences set value = '<version which is 1 number less at the end>' where variable = 'Version'; 4. koha-plack --restart kohadev 5. echo 'flush_all' | nc -q 1 memcached 11211 6. Visit http://localhost:8081/ and do the upgrade 6b. Note that the authentication and upgrade works without a problem 7. curl http://localhost:8081/cgi-bin/koha/svc/authentication -d 'userid=<koha user>&password=<koha password>' 8. koha-mysql kohadev 8a. select * from sessions; Session in MySQL sets parameters like surname, flags, interface, ip, lasttime, etc
As an aside, this would make it easier to write authentication extensions. Here is an example where the user is logged in with a new user session by supplying their cardnumber. use Modern::Perl; use CGI qw ( -utf8 ); use C4::Context; my $query = CGI->new; my $cardnumber = $query->param('cardnumber'); my $user = Koha::Patrons->find({ cardnumber => $cardnumber }); if ($user){ my $session = C4::Auth::get_session(); my $branch = $user->library; C4::Context->setup_session({ session => $session, data => { 'number', $user->borrowernumber, 'id', $user->userid, 'cardnumber', $user->cardnumber, 'firstname', $user->firstname, 'surname', $user->surname, 'branch', $branch->branchcode, 'branchname', $branch->branchname, 'flags', $user->flags, 'emailaddress', $user->email, 'interface', 'opac', }, }); my $cookie = $query->cookie( -name => 'CGISESSID', -value => $session->id, -HttpOnly => 1, -secure => ( C4::Context->https_enabled() ? 1 : 0 ), -sameSite => 'Lax' ); print $query->redirect( -uri => '/cgi-bin/koha/opac-main.pl', -cookie => $cookie, ); }
*** Bug 28507 has been marked as a duplicate of this bug. ***
Created attachment 138003 [details] [review] Bug 31050: C4::Context->setup_session() standardizes user session setup Test plan: 0. Apply patch and koha-plack --restart kohadev 1. Log into http://localhost:8081/cgi-bin/koha/mainpage.pl using "koha" user 2. Note the login is successful 3. koha-mysql kohadev 3a. select * from sessions; Session in MySQL sets parameters like surname, flags, interface, ip, lasttime, etc 3b. select * from systempreferences where variable = 'Version'; 3c. update systempreferences set value = '<version which is 1 number less at the end>' where variable = 'Version'; 4. koha-plack --restart kohadev 5. echo 'flush_all' | nc -q 1 memcached 11211 6. Visit http://localhost:8081/ and do the upgrade 6b. Note that the authentication and upgrade works without a problem 7. curl http://localhost:8081/cgi-bin/koha/svc/authentication -d 'userid=<koha user>&password=<koha password>' 8. koha-mysql kohadev 8a. select * from sessions; Session in MySQL sets parameters like surname, flags, interface, ip, lasttime, etc Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This is a nice bit of code cleaning, thanks David.. as you suggested, it might be nice as a next step to allow just passing a Patron object and then constructing the various fields from that.. could have a nice reduction in line count again. Signing off.
New method, new tests, please.
Bug 32178 implements enough of the functionality to close out this one I think *** This bug has been marked as a duplicate of bug 32178 ***
Then again... C4::Auth::create_basic_session() is only used for the OIDC auth, so I guess we still do have a ways to go... But I don't think I'll be working on it any time soon.