1Authen::Credential(3) User Contributed Perl DocumentationAuthen::Credential(3)
2
3
4

NAME

6       Authen::Credential - abstraction of a credential
7

SYNOPSIS

9         use Authen::Credential;
10         use Authen::Credential::plain;
11         use Getopt::Long qw(GetOptions);
12         use Config::General qw(ParseConfig);
13         use HTTP::Request;
14
15         # creation
16         $cred = Authen::Credential->new(
17             scheme => "plain",
18             name   => "system",
19             pass   => "manager",
20         );
21         # idem directly using the sub-class
22         $cred = Authen::Credential::plain->new(
23             name   => "system",
24             pass   => "manager",
25         );
26
27         # get credential from command line option
28         GetOptions(\%Option,
29             "auth=s",
30             ...
31         );
32         $cred = Authen::Credential->parse($Option{auth});
33
34         # get credential from configuration file
35         %Option = ParseConfig(-ConfigFile => "...");
36         $cred = Authen::Credential->new($Option{auth});
37
38         # access the credential attributes
39         if ($cred->scheme() eq "plain") {
40             printf("user name is %s\n", $cred->name());
41         }
42
43         # use the prepare() method to get ready-to-use data
44         $req = HTTP::Request->new(GET => $url);
45         $req->header(Authorization => $cred->prepare("HTTP.Basic"));
46

DESCRIPTION

48       This module offers abstractions of credentials, i.e. something that can
49       be used to authenticate. It allows the creation and manipulation of
50       credentials. In particular, it defines a standard string representation
51       (so that credentials can be given to external programs as command line
52       options), a standard structured representation (so that credentials can
53       be stored in structured configuration files or using JSON) and
54       "preparators" that can transform credentials into ready-to-use data for
55       well known targets.
56
57       Different authentication schemes (aka credential types) are supported.
58       This package currently supports "none", "plain" and "x509" but others
59       can be added by providing the supporting code in a separate module.
60
61       A Python implementation of the same credential abstractions is
62       available at <https://github.com/cern-mig/python-auth-credential> so
63       credentials can be shared between different programming languages.
64
65       For a given scheme, a credential is represented by an object with a
66       fixed set of string attributes. For instance, the "plain" scheme has
67       two attributes: "name" and "pass". More information is provided by the
68       scheme specific module, for instance Authen::Credential::plain.
69

STRING REPRESENTATION

71       The string representation of a credential is made of its scheme
72       followed by its attributes as key=value pairs, seperated by space.
73
74       For instance, for the "none" scheme with no attributes:
75
76         none
77
78       And the the "plain" scheme with a name and password:
79
80         plain name=system pass=manager
81
82       If needed, the characters can be URI-escaped, see URI::Escape. All non-
83       alphanumerical characters should be escaped to avoid parsing
84       ambiguities.
85
86       The string representation is useful to give a program through its
87       command line options. For instance:
88
89         myprog --uri http://foo:80 --auth "plain name=system pass=manager"
90

STRUCTURED REPRESENTATION

92       The structured representation of a credential is made of its scheme and
93       all its attributes as a string table.
94
95       Here is for instance how it could end up using JSON:
96
97         {"scheme":"plain","name":"system","pass":"manager"}
98
99       The same information could be stored in a configuration file. Here is
100       an example using the Apache syntax, which is for instance supported by
101       Config::General:
102
103         <auth>
104           scheme = plain
105           name   = system
106           pass   = manager
107         </auth>
108

METHODS

110       This module supports the following methods:
111
112       new([OPTIONS])
113           return a new credential object (class method); the OPTIONS are its
114           attributes
115
116       parse(STRING)
117           return a new credential object from its string representation
118           (class method)
119
120       hash()
121           return its structured representation as a reference to a hash
122
123       string()
124           return its string representation
125
126       check()
127           check that the credential contains the expected attributes
128
129       prepare(TARGET)
130           use the credential to prepare data for a given target (this is
131           scheme specific)
132
133       scheme()
134           return the authentication scheme of the credential
135
136       In addition, the attributes can be accessed using eponymous methods.
137       See the example in the "SYNOPSIS" section.
138

SEE ALSO

140       Authen::Credential::none, Authen::Credential::plain,
141       Authen::Credential::x509, URI::Escape,
142

AUTHOR

144       Lionel Cons <http://cern.ch/lionel.cons>
145
146       Copyright (C) CERN 2011-2015
147
148
149
150perl v5.32.0                      2020-07-28             Authen::Credential(3)
Impressum