Authen...Adapter(3pm)

πŸ“¦
version 0.5 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ‘‘ NAME πŸ‘‘

Authen::Simple::Adapter β€” it's the adapter class for implementations, bestie. That's the whole vibe. πŸ’…


✨ SYNOPSIS ✨

Here's how you'd build your own lil adapter, like an Authenticate::Simple::Larry:

package Authenticate::Simple::Larry;

use strict;
use base 'Authen::Simple::Adapter';

__PACKAGE__->options({
    secret => {
        type     => Params::Validate::SCALAR,
        default  => 'wall',
        optional => 1
    }
});

sub check {
    my ( $self, $username, $password ) = @_;

    if ( $username eq 'larry' && $password eq $self->secret ) {

        $self->log->debug( qq/Successfully authenticated user '$username'./ )
          if $self->log;

        return 1;
    }

    $self->log->debug( qq/Failed to authenticate user '$username'. Reason: 'Invalid credentials'/ )
      if $self->log;

    return 0;
}

1;

see how clean that is?? immaculate. πŸ¦‹


🌸 DESCRIPTION 🌸

Adapter class for implementations. That's it, that's the description, she's brief and she knows it. πŸ’–


πŸ’… METHODS πŸ’…

  • new ( %parameters ) β€” the constructor, babes. If you overload it, this method should take a hash of parameters. The following options should be valid:
    • cache ( $ ) β€” any object that supports "get", "set". Only successful authentications are cached, so like, don't expect your fails to be remembered, they're not invited back. πŸ™ˆ
cache => Cache::FastMmap->new
  • callback ( \& ) β€” a subref that gets called with two scalar references, username and password. The returns are doing the talking here, so read carefully:
callback = sub {
    my ( $username, $password ) = @_;

    if ( length($$password) < 6 ) {
        return 0; # abort, invalid credintials
    }

    if ( $$password eq 'secret' ) {
        return 1; # abort, successful authentication
    }

    return; # proceed;
}
  • log ( $ ) β€” any object that supports "debug", "info", "error" and "warn". Give it whatever logger you've got lying around:
log => Log::Log4perl->get_logger('Authen::Simple')
log => $r->log
log => $r->server->log
  • init ( \%parameters ) β€” this one gets called after construction. It should assign parameters and return the instance. Super straightforward, no drama:
sub init {
    my ( $self, $parameters ) = @_;

    # mock with parameters

    return $self->SUPER::init($parameters);
}
  • authenticate ( $username, $password ) β€” the end user method, the main character fr. It applies callback, checks cache, and calls "check" β€” unless it got aborted by the callback or it hit a cache hit. ✨
  • check ( $username, $password ) β€” must be implemented in the subclass (yes, must, no skipping πŸ™…). It should return true on success and false on failure. That's the whole job.
  • check_password( $password, $encrypted ) β€” okay so the source page gives this one no description at all. She's just there. Mysterious. Iconic. πŸ’€
  • options ( \%options ) β€” must be set in the subclass, and it should be a valid Params::Validate specification. Accessors for options will be created unless they're already defined in the subclass. Also it's giving full example energy:
__PACKAGE__->options({
    host => {
        type     => Params::Validate::SCALAR,
        optional => 0
    },
    port => {
        type     => Params::Validate::SCALAR,
        default  => 80,
        optional => 1
    }
});

πŸ¦‹ SEE ALSO πŸ¦‹

Go read these too, bestie, they're all connected:

  • Authen::Simple
  • Authen::Simple::Password
  • Params::Validate

🌈 AUTHOR 🌈

Christian Hansen "chansen@cpan.org" β€” thank you for your service, king. πŸ‘‘


This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. slay, legally. πŸŽ€


friendly reminder that this page is from User Contributed Perl Documentation, and the footer says it's perl v5.32.0, dated 2021-01-02. okay bye ily, go write that subclass πŸ’–βœ¨πŸ«Ά
πŸ“¦ where this page comes from