Subject: | error-checking of call to Auth::ActiveDirectory->authenticate() |
A user on irc.perl.org/#dancer was having problems using Dancer2::Plugin::Auth::ActiveDirectory, and in looking in to it, I see that the plugin does not appear to error-check the result from Auth::ActiveDirectory->authenticate() correctly.
It checks for $user->{error}, but he documentation for Auth::ActiveDirectory says:
# returns object from logged in user or undef if it fails
my $user = $obj->authenticate( $args{username}, $args{password} );
The patch below should resolve it, and also improves the documentation a little.
I've not tested it, though, as I don't have an ActiveDirectory testbed to try it against.
--- /home/davidp/tmp/vimbackups/ActiveDirectory.pm_20200109-095103 2016-12-30 06:32:51.000000000 +0000
+++ lib/Dancer2/Plugin/Auth/ActiveDirectory.pm 2020-01-09 09:52:34.397872270 +0000
@@ -129,14 +129,16 @@
=head2 authenticate
-Basicaly the subroutine for authentication in the ActiveDirectory
+Authenticate the user against ActiveDirectory; calls
+L<Auth::ActiveDirectory/authenticate> and reutrns a hashref of information
+about the found user, if authentication was successful, or undef if not.
=cut
register authenticate => sub {
my ( $dsl, $name, $pass ) = @_;
my $user = _connect_to_ad($dsl)->authenticate( $name, $pass );
- return $user if $user->{error};
+ return $user if !$user;
my $user_groups = [ map { $_->name } @{ $user->groups } ];
return {
uid => $user->uid,