Authen::Credential(3)

πŸ“¦
version 1.2 Β· 3 versions
, in fedora 43

πŸ’– Authen::Credential πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation, and it's literally all about Authen::Credential β€” the icon, the moment, the credential abstraction itself. grab a strawberry drink and let's get into it πŸ“


✨ NAME ✨

Authen::Credential β€” abstraction of a credential. that's it, that's the vibe. πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

  use Authen::Credential;
  use Authen::Credential::plain;
  use Getopt::Long qw(GetOptions);
  use Config::General qw(ParseConfig);
  use HTTP::Request;

  # creation
  $cred = Authen::Credential->new(
      scheme => "plain",
      name   => "system",
      pass   => "manager",
  );
  # idem directly using the sub-class
  $cred = Authen::Credential::plain->new(
      name   => "system",
      pass   => "manager",
  );

  # get credential from command line option
  GetOptions(\%Option,
      "auth=s",
      ...
  );
  $cred = Authen::Credential->parse($Option{auth});

  # get credential from configuration file
  %Option = ParseConfig(-ConfigFile => "...");
  $cred = Authen::Credential->new($Option{auth});

  # access the credential attributes
  if ($cred->scheme() eq "plain") {
      printf("user name is %s\n", $cred->name());
  }

  # use the prepare() method to get ready-to-use data
  $req = HTTP::Request->new(GET => $url);
  $req->header(Authorization => $cred->prepare("HTTP.Basic"));

no cap, that's the whole glow-up in one block. πŸ’…


🌈 DESCRIPTION 🌈

so like, this module hands you abstractions of credentials β€” meaning a thing you can use to authenticate, bestie. it lets you create and manipulate credentials. and it's not just vibing, it's structured:

  • it defines a standard string representation, so credentials can be handed to external programs as command line options
  • it defines a standard structured representation, so credentials can live in structured configuration files or in JSON
  • it gives you "preparators" that transform credentials into ready-to-use data for well known targets

different authentication schemes (aka credential types, same thing different name, iykyk) are supported. right now this package supports "none", "plain" and "x509" β€” but more can be added by providing the supporting code in a separate module. very main character energy of you tbh. ✨

there's also a Python implementation of the same credential abstractions living at https://github.com/cern-mig/python-auth-credential, so credentials can be shared between different programming languages. multilingual queen. 🌍

for a given scheme, a credential is represented by an object with a fixed set of string attributes. for instance, the "plain" scheme has two attributes: name and pass. more info lives in the scheme specific module, for instance Authen::Credential::plain. πŸ¦‹


🌸 STRING REPRESENTATION 🌸

the string representation of a credential is made of its scheme followed by its attributes as key=value pairs, seperated by space.

for instance, for the "none" scheme with no attributes:

  none

and the the "plain" scheme with a name and password:

  plain name=system pass=manager

if needed, the characters can be URI-escaped, see URI::Escape. all non-alphanumerical characters should be escaped to avoid parsing ambiguities. don't skip that part, it's giving chaos otherwise. 😭

the string representation is useful to give a program through its command line options. for instance:

  myprog --uri http://foo:80 --auth "plain name=system pass=manager"

🧚 STRUCTURED REPRESENTATION 🧚

the structured representation of a credential is made of its scheme and all its attributes as a string table. a whole little organized baddie. πŸ’œ

here is for instance how it could end up using JSON:

  {"scheme":"plain","name":"system","pass":"manager"}

the same information could be stored in a configuration file. here is an example using the Apache syntax, which is for instance supported by Config::General:

  <auth>
    scheme = plain
    name   = system
    pass   = manager
  </auth>

πŸ‘‘ METHODS πŸ‘‘

this module supports the following methods, and bestie they all ate:

  • new([OPTIONS]) β€” return a new credential object (class method); the OPTIONS are its attributes
  • parse(STRING) β€” return a new credential object from its string representation (class method)
  • hash() β€” return its structured representation as a reference to a hash
  • string() β€” return its string representation
  • check() β€” check that the credential contains the expected attributes
  • prepare(TARGET) β€” use the credential to prepare data for a given target (this is scheme specific)
  • scheme() β€” return the authentication scheme of the credential

in addition, the attributes can be accessed using eponymous methods. see the example in the "SYNOPSIS" section. 🫢


⭐ SEE ALSO ⭐

  • Authen::Credential::none
  • Authen::Credential::plain
  • Authen::Credential::x509
  • URI::Escape

go read those too, they're the supporting cast and they're all iconic. πŸ’–


πŸŽ€ AUTHOR πŸŽ€

Lionel Cons <http://cern.ch/lionel.cons>

Copyright (C) CERN 2011-2015


okay that's the whole page, you're officially credential-literate, no cap. this one's perl v5.42.0, dated 2025-07-25, and it lives at Authen::Credential(3) β€” go forth and authenticate, queen. πŸ’…βœ¨πŸŒˆ

πŸ“¦ where this page comes from