chiark / gitweb /
a5c8a3e18f3495f0ed1c870e98201df24715fd10
[cgi-auth-flexible.git] / caf.pod
1 # -*- fundamental -*-
2
3 # This is part of CGI::Auth::Flexible, a perl CGI authentication module.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version, with the "CAF Login Exception"
9 # as published by Ian Jackson (version 1, or at your option any 
10 # later version) as an Additional Permission.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Affero General Public License for more details.
16
17
18 =head1 NAME
19
20 CGI::Auth::Flexible - web authentication optionally using cookies
21
22 =head1 SYNOPSYS
23
24  my $verifier = CGI::Auth::Flexible->new_verifier(setting => value,...);
25  my $authreq = $verifier->new_request($cgi);
26
27  # simple applications
28  $authreq->check_ok() or return;
29
30  # sophisticated applications
31  my $divert_kind = $authreq->check_divert();
32  if ($divert_kind) { ... print diversion page and quit ... }
33
34  # while handling the request
35  $user = $authreq->get_username();
36  $authreq->check_mutate();
37
38 =head1 DESCRIPTION
39
40 CGI::Auth::Flexible is a library which you can use to add a
41 forms/cookie-based login facility to a Perl web application.
42
43 CGI::Auth::Flexible doesn't interfere with your application's URL path
44 namespace and just needs a few (configurable) form parameter and
45 cookie name(s) for its own use.  It tries to avoid making assumptions
46 about the implementation structure of your application.
47
48 Because CGI::Auth::Flexible is licenced under the AGPLv3, you will
49 probably need to provide a facility to allow users (even ones not
50 logged in) to download the source code for your web app.  Conveniently
51 by default CGI::Auth::Flexible provides (for pure Perl webapps) a
52 mechanism for users to get the source.
53
54 CGI::Auth::Flexible is designed to try to stop you accidentally
55 granting access by misunderstanding the API.  (Also it, of course,
56 guards against cross-site scripting.)  You do need to make sure to
57 call CGI::Auth::Flexible before answering AJAX requests as well as
58 before generating HTML pages, of course, and to call it in every
59 entrypoint to your system.
60
61 =head2 CHECKLIST
62
63 As a minimum you need to do all of the things on this checklist, where
64 applicable.  The items marked SECURITY are the ones that you might
65 forget: without them your application may appear to work, but will be
66 insecure.
67
68 =over
69
70 =item *
71
72 Call C<new_verifier> (once at application startup)
73
74 =item *
75
76 Call C<new_request> (once per request)
77
78 =item *
79
80 B<SECURITY>: Call C<check_ok> or C<check_divert> on every request, and
81 honour the return value.
82
83 =item *
84
85 If you're using C<check_ok>, implement either the
86 C<username_password_error> or C<login_ok> hook and provide it as
87 a setting to C<new_verifier>.
88
89 =item *
90
91 Provide the setting C<dir> (or provide absolute paths for all the
92 other relevant settings).
93
94 =item *
95
96 Call C<get_username> when you need to know who's logged in.
97
98 =item *
99
100 B<SECURITY>: Call C<check_mutate> or C<mutate_ok>, if you specified
101 C<promise_check_mutate>.
102
103 =item *
104
105 B<SECURITY>: Call C<check_nonpage> for every request which is not a page load
106 (if your application has any of those).
107
108 =item *
109
110 When generating URLs and forms (including AJAX requests), include the
111 hidden form parameter using C<secret_hidden_val> or
112 C<secret_hidden_html> when appropriate (see below).
113
114 =item *
115
116 B<SECURITY>: If you do not override the source provision facility (see
117 L</SOURCE CODE DOWNLOAD>), check that the assumptions it makes aren't
118 going to leak security-critical data.
119
120 =item *
121
122 Set up HTTPS on your webserver, or set the C<encrypted_only> setting
123 to a false value.
124
125 =back
126
127 These points will now be covered in more detail.
128
129 =head2 INITIALISATION
130
131 Your application should, on startup (eg, when it is loaded by
132 mod_perl) do
133 C<< $verifier = CGI::Auth::Flexible->new_verifier(settings...) >>.
134 This call can be expensive and is best amortised.
135
136 The resulting verifier object can be used to process individual
137 requests, in each case with
138 C<< $authreq = CGI::Auth::Flexible->new_request($cgi) >>.
139
140 See L</SETTINGS>.
141
142 =head2 CHECKING AND RESPONSE GENERATION
143
144 If the user is logged in, your application is to handle the request.
145 Otherwise, the user needs to be presented with a login form or error
146 message, as appropriate.  CGI::Auth::Flexible provides two alternative
147 interfaces for this:
148
149 =head3 Simple applications
150
151 The simplest usage is to call C<< $request->check_ok() >> which will
152 check the user's authentication.  If the user is not logged in it will
153 generate a login form (or redirection or other appropriate page) and
154 return false; your application should not then process that request
155 any further.  If the user is logged in it will return true.
156
157 Various hooks are provided to customise the responses generated by
158 C<check_ok>.
159
160 After C<check_ok> returns true you should go ahead and process the
161 request; you can use C<< $request->get_username >> to find out which
162 user the request came from.
163 You may also need to call C<check_mutate> and/or C<check_nonpage>
164 - see below.
165
166 =head3 Sophisticated applications
167
168 If you want to handle the control flow and to generate login forms,
169 redirections, etc., yourself, you can say
170 C<< $divert = $request->check_divert >>.  This returns undef if
171 the user is logged in, or a I<divert spec> if some kind of login
172 page or diversion should be generated.  See L</DIVERT SPEC> below for
173 details of how to deal with the return value.
174
175 =head2 MUTATING OPERATIONS AND EXTERNAL LINKS
176
177 =head3 Mutation-ignorant applications
178
179 By default CGI::Auth::Flexible does not permit external deep links
180 into your site.
181 All GET requests give a "click to continue" page which
182 submits a form which loads your app's main page.  In this
183 configuration all your application's forms and AJAX requests should
184 use C<POST>.
185
186 Such applications are also not able to provide user-specific CSS
187 stylesheets, javascript, favicons, etc.
188
189 This restriction arises from complicated deficiencies
190 in the web's security architecture.
191
192 =head3 Mutation-aware applications
193
194 The alternative is for your application to always make a special check
195 when the incoming request is going to do some kind of action (such as
196 modifying the user's setup, purchasing goods, or whatever) rather than
197 just retrieve and/or display information.  We term such requests
198 "mutating" requests.
199
200 Then non-mutating pages can be linked to from other, untrustworthy,
201 websites.
202
203 To support external links, and C<GET> requests, pass
204 C<< promise_check_mutate => 1 >> in I<settings>, and then call
205 C<< $authreq->check_mutate() >> before taking any actions.  If the
206 incoming request is not suitable then C<< $authreq->check_mutate() >>
207 will call C<die>.
208
209 There have to be no mutating C<GET> requests in your application (but
210 you shouldn't have any of those anyway); if there are, they won't
211 work.  (CGI::Auth::Flexible will spot them and cause them to fail,
212 rather than allow them to be insecure.)
213
214 =head2 GENERATING URLS, FORMS AND AJAX QUERIES
215
216 When you generate a URL, C<POST> form or AJAX request you may need to
217 include a secret hidden form parameter for the benefit of
218 CGI::Auth::Generic.  This form parameter will be checked by
219 C<check_ok>/C<check_divert> and should be ignored by your application.
220
221 By default the hidden parameter is called C<caf__assochash>.
222
223 After calling C<check_ok> or C<check_divert> the value to put in your
224 form can be obtained from C<secret_hidden_val>; C<secret_hidden_html>
225 will generate the whole HTML C<< <input...> >> element.
226
227 =head3 Mutation-ignorant applications
228
229 For mutation-ignorant applications (see above), all forms etc. should
230 include the hidden parameter (and as discussed, they must all use
231 POST rather than GET).
232
233 =head3 Mutation-aware applications
234
235 For mutation-aware applications, whether to include the secret
236 parameter depends on the kind of request.  CGI::Auth::Flexible knows
237 when it is necessary.  You should find out by calling
238 C<need_add_hidden>.
239
240 If it is inconvenient to call C<need_add_hidden> at runtime, you can
241 rely instead on the following promises:  All POST requests (which
242 includes all mutating requests) need the parameter.  The return value
243 of need_add_hidden depends only on the $method and $reqtype
244 parameters, so you can query it once and remember the answer.
245 HTML page load GETs do not need the parameter.  It is better to
246 err on the side of including the parameter.
247
248 If you really must, you can call C<need_add_hidden> "on the bench"
249 during development and bake the answer into your application code
250 structure.  However, if you do that and a new vulnerability was
251 discovered which is fixed by changing the answer, updating
252 CGI::Auth::Flexible wouldn't be sufficient to fix it.
253
254 =head3 Mutation-aware applications - non-page requests
255
256 If your mutation-aware application supports non-page resources (AJAX
257 and JSON requests, stylesheets, favicons, etc.) it must inform
258 CGI::Auth::Flexible when it is handling such a request, by calling
259 C<check_nonpage>.
260
261 Normally C<check_nonpage> will simply return (and you can ignore the
262 return value).  However, if there is an attack (or, perhaps, a bug) it
263 will die, stopping the attack.
264
265 (You do not need to call C<check_nonpage> for POST requests, but it is
266 harmless to do so.)
267
268 =head3 Mutation-aware applications - novel kinds of request
269
270 If you want to support a kind of request perhaps not yet known about
271 by CGI::Auth::Flexible, you can provide information about that new
272 request kind using C<update_get_need_add_hidden>.
273
274 =head2 DATA STORAGE
275
276 CGI::Auth::Flexible needs to store various information in plain files;
277 it does this in the directory specified by the C<dir> parameter.
278
279 =head1 SOURCE CODE DOWNLOAD
280
281 By default, CGI::Auth::Flexible provides a facility for users to
282 download the source code for the running version of your web
283 application.
284
285 This facility makes a number of important assumptions which you need
286 to check.  Note that if the provided facility is not sufficient
287 because your application is more sophisticated than it copes with (or
288 if you disable the builtin facility), you may need to implement a
289 functioning alternative to avoid violating the AGPLv3 licence.
290
291 Here are the most important (default) assumptions:
292
293 =over
294
295 =item *
296
297 Your app's source code is available by looking at @INC, $0 and
298 S<$ENV{'SCRIPT_FILENAME'}> (the B<source items>).  See
299 C<srcdump_listitems>.  Where these point to files or directories under
300 revision control, the source item is the whole containing vcs tree.
301
302 =item *
303
304 Specifically, there are no compiled or autogenerated Perl
305 files, Javascript resources, etc., which are not contained in one of
306 the source item directories.  (Files which came with your operating
307 system install don't need to be shipped as they fall under the system
308 library exception.)
309
310 =item *
311
312 You have not installed any modified versions of system
313 libraries (including system-supplied Perl modules) in C</usr> outside
314 C</usr/local>.  See C<srcdump_system_dir>.
315
316 =item *
317
318 For each source item in a dvcs, the entire dvcs history does
319 not contain anything confidential (or libellous).  Also, all files which
320 contain secrets are in the dvcs's I<.ignore> file.  See
321 C<srcdump_vcsscript_git> et al.
322
323 =item *
324
325 For each source item NOT in a dvcs, there are no confidential
326 files with the world-readable bit set (being in a world-inaccessible
327 directory is not sufficient).  See C<srcdump_excludes>.
328
329 =item *
330
331 You have none of your app's source code in C</etc>.
332
333 =item *
334
335 You don't regard pathnames on your server as secret.
336
337 =item *
338
339 You don't intentionally load Perl code by virtue of C<.>
340 being in C<@INC> by default.  (See C<srcdump_filter_cwd>.)
341
342 =back
343
344 =head1 MAIN FUNCTIONS AND METHODS
345
346 =over
347
348 =item C<< CGI::Auth::Flexible->new_verifier(setting => value, ...) >>
349
350 Initialises an instance and returns a verifier object.
351 The arguments are setting pairs like a hash initialiser.
352 See L</SETTINGS> below.
353
354 =item C<< $verifier->new_request($cgi) >>
355
356 Prepares to process a request.  I<$cgi> should normally
357 be the query object from L<CGI(3perl)>.  Most of the default
358 hook methods assume that it is; however if you replace enough of
359 the hook methods then you can pass any value you like and it
360 will be passed to your hooks.
361
362 The return value is the authentication request object (I<$authreq>)
363 which is used to check the incoming request and will contain
364 information about its credentials.
365
366 =item C<< $authreq->check_divert() >>
367
368 Checks whether the user is logged in.  Returns undef if the user is
369 logged in and we should service the request.  Otherwise returns a
370 divert spec (see L</DIVERT SPEC>) saying what should happen instead.
371
372 This method may die if it doesn't like the request, in which case
373 the request needs to be rejected.
374
375 =item C<< $authreq->check_ok() >>
376
377 Checks whether the user is logged in.  Returns true if the user is
378 logged in and we should service the request.
379
380 Otherwise it handles the request itself, generating any appropriate
381 redirect, login form, or continuation page.  It then returns false and
382 the application should not process the request further.
383
384 =item C<< $verifier->disconnect() >>
385
386 Discards the resources (open files, etc.) in the verifier object.
387
388 =back
389
390 =head1 REQUEST-RELATED FUNCTIONS AND METHODS
391
392 All of these are only valid after C<check_divert> or C<check_ok> has
393 been called.  (In the case of C<check_ok> it won't normally be sensible
394 to call these functions unless C<check_ok> returned true.)
395
396 =over
397
398 =item C<< $authreq->get_divert() >>
399
400 Returns the value previously returned by C<check_divert>.
401
402 =item C<< $authreq->get_username() >>
403
404 Returns the name of the logged-in user.  If the user was not logged
405 in (or their session had timed out, or something), returns undef.
406
407 =item C<< $authreq->check_mutate() >>
408
409 Declares to CGI::Auth::Generic that the request being handled will
410 "mutate".  That is, it will modify some server-side state (eg, adding
411 items to shopping baskets, posting messages to blogs, sending emails,
412 or whatever).
413
414 If you have set the setting C<promise_check_mutate> you must call
415 C<check_mutate> whenever appropriate.  If you haven't then it's
416 irrelevant.  See L<MUTATING OPERATIONS AND EXTERNAL LINKS>.
417
418 C<check_mutate> will either return successfully, indicating that all
419 is well and the request should proceed, or it will die.  If it dies
420 that means that the request was improper, which can only result from a
421 bug or an attack.  So an "internal server error" is a suitable
422 response.
423
424 =item C<< $authreq->check_nonpage($method, $reqtype) >>
425
426 Declares to CGI::Auth::Generic that the request is not a page request,
427 but rather a request of type I<$reqtype>.
428
429 If your application has set the setting C<promise_check_mutate>,
430 whenever it is handling anything except an HTML page loads, it must
431 call this function.  See L</REQUEST TYPES>, and
432 L<GENERATING URLS, FORMS AND AJAX QUERIES>.
433
434 C<check_nonpage> will either return successfully, indicating that all
435 is well and the request should proceed, or it will die, like
436 C<check_mutate>.
437
438 =back
439
440 =head1 RESPONSE-RELATED FUNCTIONS AND METHODS
441
442 =over
443
444 =item C<< $authreq->url_with_query_params($params, [$nonpagetype]) >>
445
446 Convenience function which returns a url for a GET request to this
447 application.
448
449 I<$params> is a hashref specifying the parameters and the PATH_INFO
450 (not including any parameters related to CGI::Auth::Flexible).
451 The keys are the parameter names, and the values are array refs with
452 the parameter value(s) (as strings, as yet unquoted).  (They are array
453 refs because it is possible to pass multiple values for the same
454 parameter in a single request; normally each arrayref would be a
455 singleton.)
456
457 The request path will be the path to the application.  If a parameter
458 with name C<< '' >> is supplied, it is taken as the PATH_INFO - its
459 value will be appended to the application path.  (It should normally
460 start with C<< / >>, and only one value should be supplied.)
461
462 =item C<< something->need_add_hidden($method, $reqtype) >>
463
464 Enquires whether a request of type I<$reqtype> using HTTP method
465 I<$method> needs the hidden form parameter.  See L</REQUEST TYPES>.
466
467 =item C<< something->secret_hidden_val() >>
468
469 Returns the value of the hidden form parameter.  This should be
470 included in all POST requests to your application (and thus be a
471 hidden form parameter in all forms).
472
473 It should also be in some (maybe all) GET requests.  If your
474 application is mutation-ignorant, it should be in all GET requests.
475 If you are mutation-aware, you need to consult C<need_add_hidden>.
476
477 The name of the hidden parameter is the setting C<assoc_param_name>,
478 C<caf_hassochash> by default.  xxx rename param and setting
479
480 =item C<< something->secret_hidden_html() >>
481
482 Returns the HTML for an C<INPUT> element specifying the hidden form
483 parameter.
484
485 =item C<< something->secret_cookie_val() >>
486
487 Returns the value of the secret cookie.  CGI::Auth::Flexible sets this
488 cookie in the forms generated by C<check_ok>.  You may also set it
489 yourself (and indeed you must do so if you use C<check_divert>).
490
491 =item C<< $authreq->_chain_params() >>
492
493 Returns a hash of the "relevant" parameters to this request, in a form
494 suitable for C<url_with_query_params>.  This is all of the query
495 parameters which are not related to CGI::Auth::Flexible.  The
496 PATH_INFO from the request is returned as the parameter C<< '' >>.
497
498 =back
499
500 =head1 OTHER FUNCTIONS AND METHODS
501
502 =over
503
504 =item C<< $verifier_or_authreq->hash($data) >>
505
506 Hashes the supplied data using the hash function specified by the
507 C<hash_algorithm> setting, and converts the result to a string of hex
508 digits.
509
510 =item C<< something->update_get_need_add_hidden($reqtype, $value, [$force]) >>
511
512 Updates CGI::Auth::Generic's knowledge about the various kinds of
513 request, and whether they need the hidden form parameter.  This
514 function applies only to GET requests - POST requests always use the
515 parameter.
516
517 I<$reqtype> is the request type (the value which will be passed to
518 C<check_nonpage> and C<need_add_hidden>.  If you are supporting a new
519 I<$reqtype> you shouuld coordinate with CGI::Auth::Flexible upstream,
520 or other users, to assign a unique request type name.
521
522 This method may be called on an authreq or a verifier, in which case
523 it will affect all authreqs using the same verifier.  Or it may be
524 called on the class as a whole, in which case it will affect the
525 global default list for all verifiers.
526
527 If I<$force> is supplied and true, this will override
528 CGI::Auth::Flexible's existing knowledge.  Otherwise this new setting
529 will be ignored if CGI::Auth::Flexible already knows about the request
530 type.  (When called on a verifier or authreq, it will ignore the
531 update in favour of existing knowledge recorded both globally in the
532 class or due to previous requests on the same verifier.)
533
534 See L</REQUEST TYPES>.
535
536 =item C<< CGI::Auth::Flexible::srcdump_dir_cpio($cgi,$verifier,$dumpdir,$dir,$outfn,$how,$script) >>
537
538 Helper function for implementing the C<srcdump_process_item> hook.
539 Generates a tarball using cpio and includes it in the prepared source
540 code distribution.
541
542 The arguments are mostly the same as for that hook.  C<$dir> is the
543 root directory at which to start the archive.  C<$how> is a short text
544 string which will be mentioned in the log.
545
546 C<$script> is a shell script fragment which must output a
547 nul-separated list of filenames (e.g. the output of C<find -print0>).
548 It is textually surrounded by C<( )> and will be executed with C<set -e>
549 in force.  Its cwd will be C<$dir>.
550
551 =item C<< $verifier_or_authreq->($data) | CGI::Auth::Flexible-> >>
552
553 Hashes the supplied data using the hash function specified by the
554 C<hash_algorithm> setting, and converts the result to a string of hex
555 digits.
556
557 =back
558
559 =head1 REQUEST TYPES
560
561 The C<$reqtype> values understood by C<check_nonpage> are strings.
562 They are:
563
564 =over
565
566 =item C<PAGE>
567
568 A top-level HTML page load.  May contain confidential information for
569 the benefit of the logged-in user.
570
571 =item C<FRAME>
572
573 An HTML frame.  May contain confidential information for
574 the benefit of the logged-in user.
575
576 =item C<IFRAME>
577
578 An HTML iframe.  May contain confidential information for
579 the benefit of the logged-in user.
580
581 =item C<SRCDUMP>
582
583 Source dump request, whether for the licence or actual source code
584 tarball; returned value is not secret.
585
586 =item C<STYLESHEET>
587
588 CSS stylesheet.  B<MUST NOT> contain any confidential data.  If the
589 stylesheet depends on the user, then attackers may be able to
590 determine what stylesheet the user is using.  Hopefully this is not a
591 problem.
592
593 =item C<FAVICON>
594
595 "Favicon" - icon for display in the browser's url bar etc.  We aren't
596 currently aware of a way that attackers can get a copy of this.
597
598 =item C<ROBOTS>
599
600 C<robots.txt>.  Should not contain any confidential data (obviously).
601
602 =item C<IMAGE>
603
604 Inline image, for an C<< <img src=...> >> element.
605
606 Unfortunately it is not possible to sensibly show top-level
607 confidential images (that is, have the user's browser directly visit a
608 url which resolves to an image rather than an HTML page with an inline
609 image).  This is because images need to have a per-session hidden form
610 parameter to avoid cross-site scripting, which breaks bookmarks etc.
611
612 =item C<SCRIPT>
613
614 JavaScript for a C<< <script> >> element.  (Possibly confidential for
615 the user.)
616
617 =item C<AJAX-XML>
618
619 C<< XMLHttpRequest >> returning XML data.  (Possibly
620 confidential for the user.)
621
622 =item C<AJAX-JSON>
623
624 C<< XMLHttpRequest >> returning JSON data.  (Possibly
625 confidential for the user.)
626
627 =item C<AJAX-OTHER>
628
629 C<< XMLHttpRequest >> returning data of some other kind.  (Possibly
630 confidential for the user.)
631
632 =back
633
634 =head1 DIVERT SPEC
635
636 The return value from C<check_divert> indicates how the request should
637 be handled.  It is C<undef> if all is well and the user is logged in.
638
639 Otherwise the return value is a hash ref with the following keys:
640
641 =over
642
643 =item C<Kind>
644
645 Scalar string indicating the kind of diversion required.
646
647 =item C<Message>
648
649 Scalar string for display to the user in relation to the diversion.
650 Has already been translated.  In HTML but normally does not contain
651 any tags.
652
653 =item C<CookieSecret>
654
655 The login cookie which should be set along with whatever response is
656 sent to the client.  The value in the hash is the actual value
657 of the cookie as a string.  C<undef> means no cookie setting header
658 should be sent; C<''> means the cookie should be cleared.
659
660 =item C<Params>
661
662 Provided with diversion kinds which involve
663 generating a redirection or indirection,
664 perhaps via a login form.
665
666 The extra hidden form parameters (and the C<PATH_INFO>) which should
667 be set when the subsequent request bounces back from the client, in
668 the form used by C<url_with_query_params>.
669
670 The contents of this hashref does not include the CAF-specific
671 parameters such as the secret cookie, those which follow from the kind
672 of diversion requested, etc.
673
674 It is correct to always include the contents of C<Params> as hidden
675 parameters in the urls for all redirections, and as hidden input
676 fields in all generated forms.  The specific cases where C<Params> is
677 currently relevant are also mentioned in the text for each divert
678 kind.
679
680 =back
681
682 The values of C<Kind> are:
683
684 =over
685
686 =item C<SRCDUMP->I<item>
687
688 We should respond by sending our application source code.  I<item>
689 (which will contain only word characters, and no lower case) is the
690 specific item to send, normally C<SOURCE> or C<LICENCE>.
691
692 =item C<REDIRECT-HTTPS>
693
694 We should respond with an HTTP redirect to the HTTPS instance of our
695 application.
696
697 =item C<REDIRECT-LOGGEDOUT>
698
699 We should redirect to a page showing that the user has been logged
700 out.  (Ie, to a url with one of the the C<loggedout_param_names> set.)
701
702 =item C<SMALLPAGE-LOGGEDOUT>
703
704 We should generate a page showing that the user has been logged out.
705 There can be a link on the page pointing to the login page so that the
706 user can log back in.
707
708 =item C<SMALLPAGE-NOCOOKIE>
709
710 We should generate a page reporting that the user does not have
711 cookies enabled.  It should probably contain a link pointing to the
712 login page with additionally all the parameters in C<Params>.  When
713 this divert spec is generated, C<Message> will explain the problem
714 with cookies so there is no need to do that again in the page body if
715 you include the contents of C<Message>.
716
717 =item C<LOGIN-STALE>
718
719 The user's session was stale (this is described in C<Message>).  We
720 should generate a login form.
721
722 =item C<LOGIN-BAD>
723
724 The user supplied bad login credentials.  The details are in
725 C<Message>.  We should generate a login form (with additionally the
726 parameters from C<Params> as hidden fields).
727
728 =item C<LOGIN-INCOMINGLINK>
729
730 We should generate a login form (with the specified parameters); the
731 user is entering the site via a cross-site link but is not yet logged
732 in.
733
734 =item C<LOGIN-FRESH>
735
736 We should generate a login form.  The user is not yet logged in.
737
738 =item C<REDIRECT-LOGGEDIN>
739
740 We should redirect to our actual application, with the specified
741 parameters.  (The user has just logged in.)
742
743 =item C<STALE>
744
745 The user is logged in but the incoming form submission looks like it
746 was from a stale login session.  Alternatively, it may have been
747 generated by an attacker's cross-site-scripting attack.
748
749 Naive applications should generate a small page with a form or link to
750 our own main page without any parameters.
751
752 A sophisticated application could infer from the submitted form
753 parameters what the user was allegedly trying to do.  We could then
754 generate a fresh page showing what the intended action was, with a
755 fresh form which (if the user confirm) would resubmit that action.
756 B<Great care> must be taken to avoid relying on the sanity and
757 coherence of the incoming form parameters.  We B<MUST NOT> simply
758 reproduce the incoming parameters in the new form.  It is essential
759 that the visual appearance of the generated form correctly shows to
760 the user what the action is that will be taken if the form is
761 submitted.  If that action is dangerous, the form should not look like
762 the kind of confirmation pages which the user is likely to simply
763 click through without thinking.
764
765 =item C<MAINPAGEONLY>
766
767 We should generate our main page but B<ignoring all form parameters>
768 and B<ignoring the path_info>.  Most applications will find this
769 difficult to implement.
770
771 An alternative is to generate a small page with a form or link which
772 submits our own main page without any parameters.
773
774 (Applications which set C<promise_check_mutate> do not see this divert
775 kind.)
776
777 =back
778
779 Applications should die if they are presented with a divert kind that
780 they don't recognise.
781
782 =head1 SETTINGS
783
784 C<new_verifier> and C<new_request> each take a list of settings, as
785 a list of pairs C<< key => value >> (like a Perl hash assignment).
786
787 The settings supplied to C<new_verifier> are stored in the verifier
788 and will apply to all authreqs made from it unless overridden in the
789 call to C<new_request>
790
791 When a setting is described as a hook function, it should be a
792 coderef.  The first argument will be the query object from
793 L<CGI(3perl)> (strictly, it will be whatever value was passed to
794 C<new_request>).  The second argument will be the authreq object (the
795 return value from C<new_request>).
796 Ie, C<< sub some_hook ($$...) { my ($cgi,$authreq,@stuff) = @_ ... >>
797
798 In bullet point headings, the hook functions are shown in the form
799 C<< some_hook($cgi,$authreq,@stuff) >> even though this would not be
800 legal syntax.  This should be read to mean that the
801 %implicit_settings_hash{'some_hook'}($cgi,$authreq,@stuff)
802 would be a legal call.  (However, the settings hash is not exposed.)
803
804 When a hook's default implementation is mentioned and named, that
805 function won't also be described in the section on the module's
806 functions.
807
808 =head2 GENERAL SETTINGS
809
810 =over
811
812 =item C<dir>
813
814 The directory CGI::Auth::Generic should use for its data storage.
815 This is actually just a default absolute path used when the other
816 path settings are relative values.
817
818 Must be an absolute filename.
819
820 =item C<db_dbh>
821
822 CGI::Auth::Flexible needs a database for recording users' login
823 session.  This database needs to be shared across all instances of the
824 web application, so in a multi-node cluster it needs to be your actual
825 database.
826
827 CGI::Auth::Flexible will create the table and index it needs if they
828 don't already exist, and will manage their contents.  You do not need
829 to integrate them into the rest of your webapp's data storage.  (In
830 particular, there is no need for transactional integrity across
831 changes made by CAF and your own application.)
832
833 By default, CAF uses a sqlite3 database stored on local disk in the
834 file named by C<db_path>.  This will be suitable for all
835 applications which run on a single host.
836
837 This value, if supplied, should be a DBI handle for the database.
838
839 =item C<db_dsn>
840
841 This is the DSN to pass to C<< DBI->connect >>.  Used only if
842 C<db_dbh> is not supplied.
843
844 =item C<db_path>
845
846 Path to the sqlite3 database used for CAF's session storage.  The
847 default is C<caf.db>.
848
849 Used only if neither C<db_dbh> or C<db_dsn> are supplied.
850
851 If this is a relative path, it is in C<dir>.
852
853 =item C<db_prefix>
854
855 Prefix for the SQL tables and indices to use (and to create, if
856 necessary).
857
858 See L</DATABASE TABLES>.
859
860 =item C<keys_path>
861
862 Path to the keys file used by CAF.  This arrangement will change in
863 the future.  See L</BUGS>.
864
865 =item C<random_source>
866
867 Special file to read random numbers from.  Should return
868 cryptographically secure (pseudo)-random bytes, unpredictable to
869 adversaries (even ones on the same machine).
870
871 On Linux, there is no device which is properly suitable.  This is a
872 bug in Linux.  You can use C</dev/random> which can block
873 unnecessarily even though the kernel PRNG has been properly seeded and
874 is fine, or C</dev/urandom> which might return values which attackers
875 can predict if the kernel PRNG has not been properly seeded.
876
877 The default is C</dev/urandom>.
878
879 =item C<secretbits>
880
881 Length of the assoc secret.  Defaults to 128.
882
883 =item C<hash_algorithm>
884
885 Must be a string suitable for use with C<new Digest>.
886 Defaults to C<SHA-256>.
887
888 =item C<login_timeout>
889
890 A user will be logged out this many seconds after they first logged
891 in.  Default: 86400 (one day).
892
893 =item C<login_form_timeout>
894
895 A login form becomes invalid this many seconds after it has been sent.
896 Default: 3600 seconds (one hour).
897
898 =item C<key_rollover>
899
900 The key used for generating assoc secrets is rolled over approximately
901 this often (in seconds).  Default: 86400.
902
903 =item C<assoc_param_name>
904
905 Name of the hidden form parameter.  Default: C<caf_assochash>.
906
907 =item C<cookie_name>
908
909 Name of the cookie used for login sessions.  Default:
910 C<caf_assocsecret>.
911
912 =item C<password_param_name>
913
914 Name of the password field in the login form.  Default: C<password>.
915
916 Used by C<login_ok_password> (the default C<login_ok> hook),
917 C<gen_plain_login_form> and the default C<is_login> hook.
918
919 =item C<username_param_names>
920
921 Arrayref of name(s) of username form parameters.
922
923 The first entry is used by C<login_ok_password> (the default
924 C<login_ok> hook) to pass to the C<username_password_error> hook and
925 used as the username if all is well.
926
927 All the entries are used by C<gen_plain_login_fork> (the default
928 C<gen_login_form> hook for C<check_ok>) to generate form entry fields.
929
930 The default is C<['username']>.
931
932 =item C<logout_param_names>
933
934 Arrayref of name(s) of form parameters indicating that the request is
935 a logout request.
936
937 Used by the default C<is_logout> hook.
938
939 If you want users to be able to explicitly log out, you need to
940 provide a logout button, something like
941 C<< <input type="submit" name="caf_logout" ... >>
942
943 The default is C<['caf_logout']>
944
945 =item C<logged_param_names>
946
947 Arrayref of name(s) of form parameters indicating that user has just
948 logged out.  (During the logout process, the actual logout action is a
949 POST request, whose response redirects to the "you have been logged
950 out" page; these form parameters are for this second page.)
951
952 Used by the default C<is_loggedout> hook.
953
954 The first entry is used by C<check_ok> to generate the redirection.
955
956 The default is C<['caf_loggedout']>
957
958 =item C<promise_check_mutate>
959
960 Boolean.  If true, is a declaration by the application that it is
961 mutatin-aware.  See L</MUTATING OPERATIONS AND EXTERNAL LINKS>.
962
963 The default is 0.
964
965 =item C<encrypted_only>
966
967 Boolean.  If true, CAF will insist that all transactions be done over
968 an encrypted http connection.  It will redirect unencrypted requests
969 to the https instance of the applicattion, and will set the encrypted
970 only flag on its cookie.
971
972 The default is 1.
973
974 =item C<< get_url($cgi,$authreq) >>
975
976 Hook which returns the URL of this web application.  By default, we
977 call C<< $cgi->url() >> for each request, but you can fix this if you
978 prefer.
979
980 =item C<< is_login,is_logout,is_loggedout($cgi,$authreq) >>
981
982 Hook which returns a boolean indicating whether the request was,
983 respectively: a login form submission (ie, username and password); a
984 logout request (submission resulting from the user pressing the
985 "logout" button); "logged out" page (redirection from the logout
986 POST).
987
988 The default is to check whether any of the corresponding request
989 parameters (C<< login_param_names >> etc.) was supplied, using the
990 C<get_param> hook.
991
992 =back
993
994 =head2 SETTINGS (HOOKS) RELATED TO THE CGI REQUEST OBJECT
995
996 =over
997
998 =item C<< get_param($cgi,$authreq,$param) >>
999
1000 Returns the value of a single-valued form parameter.
1001 The default is to call C<< $cgi->param($param) >>.
1002 The semantics are the same as that of C<CGI::param>.
1003
1004 =item C<< get_params($cgi,$authreq) >>
1005
1006 Returns a hash of the parameters.  The return value is a hashref whose
1007 keys are the parameter names and whose values are arrayrefs, one entry
1008 in the arrayref for each value.
1009
1010 The default is to call C<< $cgi->Vars() >>, expect the
1011 results to look like those from C<CGI::Vars>, and massage them into
1012 the required form with split.
1013
1014 =item C<< get_path_info($cgi,$authreq) >>
1015
1016 Returns the PATH_INFO of the request.  The default is to
1017 call C<< $cgi->path_info() >>.
1018
1019 =item C<< get_cookie($cgi,$authreq) >>
1020
1021 Returns the value of the CAF cookie sent with the request, or undef if
1022 none was supplied.  The default is to call C<<
1023 $cgi->cookie($cookie_name) >> (where C<$cookie_name> is from the
1024 setting of the same name).  The return value should be the scalar
1025 value of the cookie.
1026
1027 =item C<< get_method($cgi,$authreq) >>
1028
1029 Returns the HTTP method as a string.  The default is to call
1030 C<< $cgi->request_method() >>.
1031
1032 =item C<< is_https($cgi,$authreq) >>
1033
1034 Returns a boolean indicating whether the request was over an encrypted
1035 channel.  The default is C<< !!$cgi->https() >>.  See C<encrypted_only>.
1036
1037 =back
1038
1039 =head2 SETTINGS RELATED TO HTML GENERATION
1040
1041 These are only used if you call C<check_ok> (or other functions
1042 mentioned in this section).
1043
1044 Settings whose names are of the form C<gen_...> are hooks which each
1045 return an array of strings, normally HTML strings, for use by
1046 C<check_ok> (or, in turn, other hooks, or your application).  These
1047 are often documented simply by showing the output produced.  In many
1048 cases parts of the output are in turn obtained from other hooks.  In
1049 some cases the default implementations have been given names for
1050 convenient use by your application.  They will be called in array
1051 context.
1052
1053 We'll write C<gettext(something)> even though actually there is a hook
1054 to control the translation function used.
1055
1056 =over
1057
1058 =item C<handle_divert>($cgi,$authreq,$divert))
1059
1060 C<check_ok> calls this hook before producing output of its own.  If
1061 you want to handle some but not all diversions yourself, you may set
1062 this hook.  The hook should either do nothing and return false, or
1063 return true if it has handled the request (or arrange for the request
1064 to be handled).  If the hook returns true then C<check_ok> simply
1065 returns 0.
1066
1067 =item C<gen_login_form>($cgi,$authreq,$divert))
1068
1069 Default: a table (used mostly for layout) containing input fields for
1070 a login form.  Must be within a C<< <form> >> element, but doesn't
1071 generate it.  Has text fields for every entry in
1072 C<username_param_names> (in each case associated with a description
1073 C<< gettext(ucfirst $parameter_name) >>, a password field (with
1074 description C<gettext("Password")>, and a login submit button (with
1075 description C<gettext("Login")>.
1076
1077 Default is available as the module function C<gen_plain_login_form>.
1078
1079 =item C<gen_login_link>($cgi,$authreq))
1080
1081 Default:
1082
1083  <a href="http:...">gettext(Log in again to continue.)</a>
1084
1085 Default is available as the module function C<gen_plain_login_link>.
1086
1087 =item C<gen_postmainpage_form>($cgi,$authreq,$params))
1088
1089 Default: form contents (but not the C<< <form> >> element):
1090
1091 C<$params> (in the form returned by the C<get_params> hook) as hidden
1092 fields, and also:
1093
1094  <input type="submit" ... value=getext('Continue')>
1095
1096 Default is available as the module function C<gen_postmainpage_form>.
1097
1098 =item C<gen_start_html>($cgi,$authreq,$title)
1099
1100 Default: C<$cgi->start_html($title)>
1101
1102 =item C<gen_end_html>($cgi,$authreq,$title)
1103
1104 Default: C<$cgi->end_html($title)>
1105
1106 =item C<gen_footer_html>($cgi,$authreq)>
1107
1108 Default:
1109
1110  <hr><address>
1111  Powered by Free / Libre / Open Source Software
1112  according to the [gen_licence_link_html].
1113  [gen_source_link_html].
1114  </address>
1115
1116 Default is available as the module function C<gen_plain_footer_html>.
1117
1118 =item C<gen_licence_link_html>($cgi,$authreq)>
1119
1120 Default: uses C<url_with_query_params> to generate a URL for
1121 downloading the licence, and returns:
1122   <a href="...">GNU Affero GPL</a>
1123
1124 Default is available as the module function C<gen_plain_licence_link_html>.
1125
1126 =item C<gen_source_link_html>($cgi,$authreq)>
1127
1128 Default: uses C<url_with_query_params> to generate a URL for
1129 downloading the source, and returns:
1130   <a href="...">Source available</a>
1131
1132 Default is available as the module function C<gen_plain_source_link_html>.
1133
1134 =item C<form_entry_size>
1135
1136 Size of generated text entry fields.  Default is 60.
1137
1138 =item C<dummy_param_name_prefix>
1139
1140 Some of CAF's HTML-generating functions need to invent form parameter
1141 names.  They will all start with this string.  Default: C<caf__>.
1142
1143 =back
1144
1145 =head2 SETTINGS FOR SOURCE CODE DOWNLOAD FACILITY
1146
1147 =over
1148
1149 =item C<srcdump_needlogin>
1150
1151 Boolean: do users need to log in to be able to download the source
1152 code for the whole application ?  Default: 0.
1153
1154 =item C<srcdump_param_name>
1155
1156 Form parameter name used to indicate that this is a source download
1157 request.  If this parameter is supplied, C<check_ok> and
1158 C<check_divert> will arrange for the applicaton source code to be
1159 delivered as the response (in C<check_ok>'s case by doing it itself
1160 and in C<check_divert>'s case by asking your application to do so.
1161
1162 Default is C<caf_srcdump>.
1163
1164 =item C<srcdump_path>
1165
1166 Path to the directory used for storing pre-prepared source downloads.
1167 Defaults to C<caf-srcdump>.
1168
1169 If this is a relative path, it is in C<dir>.
1170
1171 =item C<srcdump_dump($cgi,$authreq,$srcobj)>
1172
1173 Dump the source code (C<$srcobj='source'> or licence data
1174 (C<$srcobj='licence'>).  The default implementation checks that
1175 C<$srcobj> has reasonable syntax and uses the files C<$srcobj.data>
1176 and C<$srcobj.ctype> with the C<dump> hook.
1177
1178 =item C<dump($cgi,$authreq,$contenttype,$datafilehandle)>
1179
1180 Responds to the request by sending the contents of $datafilehandle
1181 (which should just have been opened) and specifying a content type of
1182 $contenttype.
1183
1184 The default implmentation uses the C<print> hook, and also calls
1185 C<$cgi->header('-type' => $contenttype>, and is available as the
1186 module function C<dump_plain>.
1187
1188 =item C<srcdump_prepare($cgi,$verifier)>
1189
1190 Prepares the source code for download when requested.  Invoked by
1191 C<new_verifier>, always, immediately before it returns the
1192 just-created verifier object.
1193
1194 The default implementation is the module function
1195 C<srcdump_dirscan_prepare>, which prepares a manifest, licence file
1196 and source code tarball of tarballs, as follows:
1197
1198 It processes each entry in the return value from C<srcdump_listitems>.
1199 These are the software's include directories and any other directories
1200 containing source code.  It handles C<.> specially (see
1201 C<srcdump_filter_cwd>).
1202
1203 For each entry it looks, relative to that, for the licence as a file
1204 with a name mentioned in C<srcdump_licence_files>.  The first such
1205 file found is considered to be the licence.  It then calls the hook
1206 C<srcdump_process_item> for the entry.
1207
1208 The licence, a manifest file, and all the outputs generated by the
1209 calls to C<srcdump_process_item>, are tarred up and compressed as a
1210 single source tarball.
1211
1212 It uses the directory named by C<srcdump_path> as its directory for
1213 working and output files.  It uses the filename patterns
1214 C<generate.*>, C<licence.*>, C<s.[a-z][a-z][a-z].*>, C<manifest.*>,
1215 C<source.*> in that directory.
1216
1217 =item C<srcdump_process_item>($cgi,$verifier,$dumpdir,$item,\&outfn,\$needlicence,\%dirsdone)>
1218
1219 Processes a single include directory or software entry, so as to
1220 include the source code found there.  Called only by the default
1221 implementation of C<srcdump_prepare>.
1222
1223 C<$dumpdir> is the directory for working and output files.  C<$item>
1224 is the real (no symlinks) absolute path to the item.
1225
1226 C<\$needlicence> is a ref to a scalar: this scalar is undef if we have
1227 already found the licence file; otherwise it is the filename to which
1228 the licence should be copied.  If the referent is undef on entry,
1229 C<srcdump_process_item> needs to see if it finds the licence; if it
1230 does it should copy it to the named file and then set the scalar to
1231 undef.
1232
1233 C<\%dirsdone> is a ref to the hash used by C<srcdump_prepare> to avoid
1234 including a single directory more than once.  If
1235 C<srcdump_process_item> decides to process a directory other than
1236 C<$item> it should check this hash with the real absolute path of the
1237 other directoy as a key: if the hash entry is true, it has already
1238 been done and should be skipped; otherwise the hash entry should be set.
1239
1240 C<\&outfn> is a coderef which C<srcdump_process_item> should call each
1241 time it wants to generate a file which should be included as part of
1242 the source code.  It should be called using one of these patterns:
1243    $outfn->("message for manifest");
1244    $outfile = $outfn->("message for manifest", "extension");
1245 The former simply prints the message into the manifest in the form
1246   none: message for manifest
1247 The latter generates and returns a filename which should then
1248 be created and filled with some appropriate data.  C<"extension">
1249 should be a string for the file extension, eg C<"txt">.  The output
1250 can be written directly to the named file: there is no need to
1251 write to a temporary file and rename.  C<$outfn> writes the filename
1252 and the message to the manifest, in the form
1253   filename leaf: message
1254 In neither case is the actual name of C<$dir> on the system
1255 disclosed per se although of course some of the contents of some of
1256 the files in the source code dump may mention it.
1257
1258 The default implementation is the module function
1259 C<srcdump_process_item>.
1260
1261 It skips directories for which C<srcdump_system_dir> returns true.
1262
1263 It then searches the item and its parent
1264 directories for a vcs metadata directory (one of the names in
1265 C<srcdump_vcs_dirs>); if found, it calls the C<srcdump_byvcs> hook
1266 (after checking and updaeing C<%dirsdone>).
1267 Otherwise it calls the C<srcdump_novcs> hook.
1268
1269 =item C<srcdump_novcs($cgi,$verifier,$dumpdir,$item,$outfn)>
1270
1271 Called by the default implementation of C<srcdump_process_item>, with
1272 the same arguments, if it doesn't find vcs metadata.
1273
1274 The default implementation is the module function C<srcdump_novcs>.
1275
1276 If C<$item> is a directory, it uses C<srcdump_dir_cpio> to prepare a
1277 tarball of all the files under C<$item> which have the world read bit
1278 set.  Directories are not included (and their permissions are
1279 disregarded).  The contents of C<srcdump_excludes> are excluded.
1280
1281 If it's a plain file it uses C<srcdump_file> to include the file.
1282
1283 =item C<srcdump_byvcs($cgi,$verifier,$dumpdir,$item,$outfn,$vcs)>
1284
1285 Called by the default implementation of C<srcdump_process_item>, with
1286 the same arguments, if it finds vcs metadata.  The additional argument
1287 C<$vcs> is derived from the entry of C<srcump_vcs_dirs> which was
1288 used: it's the first sequence of word characters, lowercased.
1289
1290 The default implementation is the module function C<srcdump_byvcs>.
1291 It simply calls C<srcdump_dir_cpio> with a script from the setting
1292 C<srcdump_vcsscript>.
1293
1294 =item C<srcdump_vcs_dirs>
1295
1296 Array ref of leaf names of vcs metadata directories.  Used by the
1297 default implementation of C<srcdump_process_item>.  The default value
1298 is C<['.git','.hg','.bzr','.svn']>.
1299
1300 =item C<srcdump_vcs_script>
1301
1302 Hash ref of scripts for generating vcs metadata.  Used by the default
1303 implementation of C<srcdump_byvcs>.  The keys are values of C<$vcs>
1304 (see C<srcdump_byvcs>); the values are scripts as for
1305 C<srcdump_dir_cpio>.
1306
1307 The default has an entry only for C<git>:
1308   git ls-files -z
1309   git ls-files -z --others --exclude-from=.gitignore
1310   find .git -print0
1311
1312 =item C<srcdump_excludes>
1313
1314 Array ref of exclude glob patterns, used by the default implementation
1315 of C<srcdump_novcs>.  The default value is C<['*~','*.bak','*.tmp','#*#']>.
1316
1317 Entries must not contain C<'> or C<\>.
1318
1319 =item C<srcdump_listitems($cgi,$verifier)>
1320
1321 Returns an array of directories which might contain source code of the
1322 web application and which should be therefore be considered for
1323 including in the source code delivery.
1324
1325 Used by the default implementation of C<srcdump_prepare>.
1326
1327 Entries must be directories, plain files, or nonexistent; they may
1328 also be symlinks which resolve to one of those.
1329
1330 If C<.> is included it may be treated specially - see
1331 C<srcdump_filter_cwd>.
1332
1333 The default implementation returns 
1334 C<(@INC, $ENV{'SCRIPT_FILENAME'}, $0)>.
1335
1336 =item C<srcdump_system_dir($cgi,$verifier,$dir)>
1337
1338 Determines whether C<$dir> is a "system directory", in which any
1339 source code used by the application should nevertheless not be
1340 included in the source code dump.
1341
1342 Used by the default implementation of C<srcdump_item>.
1343
1344 The default implementation is as follows: Things in C</etc/> are
1345 system directories.  Things in C</usr/> are too, unless they are in
1346 C</usr/local/> or C</usr/lib/cgi*>.
1347
1348 =item C<srcdump_filter_cwd>
1349
1350 Boolean which controls the handling of C<.> if it appears in the
1351 return value from C<srcdump_listitems>.  Used only by the default
1352 implementation of C<srcdump_prepare>.
1353
1354 If set to false, C<.> is treated normally and no special action is
1355 taken.
1356
1357 However often the current directory may be C</>, or a data directory,
1358 or some other directory containing data which is confidential, or
1359 should not be included in the public source code distribution for
1360 other reasons.  And for historical reasons Perl has C<@INC> containing
1361 C<.> by default (which is arguably dangerous and wrong).
1362
1363 So the default this setting is true, which has the following effects:
1364
1365 C<.> is not searched for source code even if it appears in C<@INC>.
1366 C<.> is removed from C<@INC> and C<%INC> is checked to see if any
1367 modules appear to have already been loaded by virtue of C<.> appearing
1368 in C<@INC> and if they have it is treated as a fatal error.
1369
1370 Only the literal string C<.> is affected.  If the cwd is included by
1371 any other name it is not treated specially regardless of this setting.
1372
1373 =back
1374
1375 =head1 DATABASE TABLES
1376
1377 In a simple application, you do not need to worry about this.  But if
1378 your application runs on multiple frontend hosts with a shared
1379 database, you may need to create for yourself the tables and indices
1380 used by CGI::Auth::Flexible.
1381
1382 By default, every time CAF starts up, it attempts to execute certain
1383 fixed database statements to create the tables and indices it needs.
1384 These are run with C<$dbh->{PrintError}> set to 0.  The effect with
1385 sqlite (the default database) is that the tables and indices are
1386 created iff they do not already exist, and that no spurious errors are
1387 reported anywhere.
1388
1389 If you use a different database, or just prefer to do things
1390 differently, you can set up the tables yourself and/or disable or
1391 modify the default setup statements, via the C<db_setup_stmts>
1392 setting.
1393
1394 The tables needed are:
1395
1396
1397 xxx document _db_setup_do
1398 xxx make _db_setup_do explicitly overrideable
1399
1400
1401 xxx remaining settings
1402  db_password
1403  username_password_error
1404  login_ok
1405  get_cookie_domain
1406  gettext
1407  print
1408  debug
1409
1410 xxx document cookie usage
1411 xxx document construct_cookie fn
1412
1413 xxx document @default_db_setup_statements
1414
1415 xxx bugs wrong default random on Linux
1416
1417 xxx bugs wrong default random on *BSD
1418
1419 xxx bugs keys not shared should be in db
1420
1421 xxx rename caf_assocsecret default cookie name
1422
1423 xxx mention relationship between login_timeout and cookies