2 # HTTP basic auth plugin.
3 package IkiWiki::Plugin::httpauth;
10 hook(type => "getsetup", id => "httpauth", call => \&getsetup);
11 hook(type => "auth", id => "httpauth", call => \&auth);
12 hook(type => "formbuilder_setup", id => "httpauth",
13 call => \&formbuilder_setup);
14 hook(type => "canedit", id => "httpauth", call => \&canedit,
26 example => "http://example.com/wiki/auth/ikiwiki.cgi",
27 description => "url to redirect to when authentication is needed",
31 httpauth_pagespec => {
33 example => "!*/Discussion",
34 description => "PageSpec of pages where only httpauth will be used for authentication",
40 sub redir_cgiauthurl ($;@) {
43 IkiWiki::redirect($cgi,
44 @_ > 1 ? IkiWiki::cgiurl(cgiurl => $config{cgiauthurl}, @_)
45 : $config{cgiauthurl}."?@_"
54 if (defined $cgi->remote_user()) {
55 $session->param("name", $cgi->remote_user());
59 sub formbuilder_setup (@) {
62 my $form=$params{form};
63 my $session=$params{session};
65 my $buttons=$params{buttons};
67 if ($form->title eq "signin" &&
68 ! defined $cgi->remote_user() && defined $config{cgiauthurl}) {
69 my $button_text="Login with HTTP auth";
70 push @$buttons, $button_text;
72 if ($form->submitted && $form->submitted eq $button_text) {
73 # bounce thru cgiauthurl and then back to
74 # the stored postsignin action
75 redir_cgiauthurl($cgi, do => "postsignin");
80 sub test_httpauth_pagespec ($) {
92 if (! defined $cgi->remote_user() &&
93 defined $config{httpauth_pagespec} &&
94 length $config{httpauth_pagespec} &&
95 defined $config{cgiauthurl} &&
96 pagespec_match($page, $config{httpauth_pagespec})) {
98 # bounce thru cgiauthurl and back to edit action
99 redir_cgiauthurl($cgi, $cgi->query_string());