[cgiapp] Saving Data From Authentication Phase

Rhesa Rozendaal perl at rhesa.com
Tue Jan 8 14:49:19 EST 2008


adam at spatialsystems.org wrote:
> When I try that in the login coderef passed to the CGI::Application::Plugin::Authentication, I get an error about $self not being an explicit package name.  They only thing that gets passed to the coderef is the username and password, not $self.  I don't see a way to save the AD data to the session from within the \&my_login coderef.

D'oh! I completely missed that, you're right.

> Is there a way to store this into the session without modifying CGI::Application::Plugin::Authorization::Driver::Generic to get $self into the auth coderef?

You could wrap &mylogin in a closure:

> sub setup {
> 
> 	#  setup authentication
> 	$self->authen->config(
> 
> 		#  here we send coderef \&my_login for login
> 		DRIVER => [ 'Generic', \&my_login ],

DRIVER => [ 'Generic', sub { return $self->my_login( @_ ) } ],

> 		STORE => 'Session',
> 		LOGIN_RUNMODE => 'login',
> 		POST_LOGIN_RUNMODE => 'main',
> 		LOGOUT_RUNMODE => 'login',
> 	);
> 
> }
> 
> sub my_login {

my $self = shift;

> 	my ($username, $password) = @_;
> 
> 	my $ad_auth = MyCompany::ActiveDirectory->new('WINDOWS');
> 
> 	return 0 if not $ad_auth->login( $username, $password );
> 
> 	#  how do I store this info in the hash ref so I always have it???
> 	$users_hash_ref = $ad_auth->getUserInfo;
> 

  	$self->session->param( ad_auth_userinfo => $users_hash_ref );

> 
> 	return 1;
> 
> }
> 



More information about the cgiapp mailing list