[cgiapp] CGI::Application::Plugin::Authentication

Cees Hek ceeshek at gmail.com
Sun May 9 20:25:27 EDT 2010


On Sat, May 8, 2010 at 12:44 AM,  <Thomas.RAULET at biogemma.com> wrote:
>
> Hello,
>
> I'm using your Auth' plugin into my CGI::Application and I check credentials
> within a custom sub.
> I wonder if i can pass extra parameters to my sub ... ?
>
> Take a lookat my code :
> BaseWebApp.pm
> [....]
> #----------------- auth config -----------------#
>         $self->authen->config(
>                 DRIVER => ['Generic',\&auth],
>                 STORE => 'Session',
>                 LOGOUT_RUNMODE => 'logout',
>                 LOGIN_SESSION_TIMEOUT => {
>                         IDLE_FOR =>
> $self->config_param('authen_idle_expiry')
>                 },
>                 RENDER_LOGIN => \&login_form
>         );
> [...]
> #---------------------------------------------------------------------------------------------
> sub auth {
> my @credential = @_;
> my $obj = __PACKAGE__->new(
>     arg1 => 'some_arg_hard_writed',
>     arg2    => 'some_arg_hard_writed',
>     arg3 => 'some_arg_hard_writed');
> [...]
> }
>
>
> Just after "\&auth_ldap", I would pass $self->config_param list in order to
> retrieve some config params that my sub needs...rather than hard writes too
> many agrs ... ;)

Hi Thomas,

Any questions about CGI::Application plugins should be sent to the
mailing list.  That way other people can benefit from the questions
and the answers.

As for your issue, you could create your check method as a closure and
access variables that are set outside of the method:

    my $arg1 = $self->config_param('...');
    my $arg2 = $self->config_param('...');
    my $auth_sub = sub {
        my @credential = @_;
        my $obj = __PACKAGE__->new(
            arg1 => $arg1,
            arg2 => $arg2,
        );
        [...]
    }

    $self->authen->config(
                DRIVER => ['Generic',$auth_sub],
                STORE => 'Session',
                LOGOUT_RUNMODE => 'logout',
                LOGIN_SESSION_TIMEOUT => {
                    IDLE_FOR => $self->config_param('authen_idle_expiry')
                },
                RENDER_LOGIN => \&login_form
    );

You could even access $self directly from within the auth_sub method,
but that is a bit dangerous because it can potentially cause circular
references.

Cheers,

Cees Hek


More information about the cgiapp mailing list