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,
27 example => "http://example.com/wiki/auth/ikiwiki.cgi",
28 description => "url to redirect to when authentication is needed",
32 httpauth_pagespec => {
34 example => "!*/Discussion",
35 description => "PageSpec of pages where only httpauth will be used for authentication",
41 sub redir_cgiauthurl ($;@) {
44 IkiWiki::redirect($cgi,
45 @_ > 1 ? IkiWiki::cgiurl(cgiurl => $config{cgiauthurl}, @_)
46 : $config{cgiauthurl}."?@_"
55 if (defined $cgi->remote_user()) {
56 $session->param("name", $cgi->remote_user());
60 sub formbuilder_setup (@) {
63 my $form=$params{form};
64 my $session=$params{session};
66 my $buttons=$params{buttons};
68 if ($form->title eq "signin" &&
69 ! defined $cgi->remote_user() && defined $config{cgiauthurl}) {
70 my $button_text="Login with HTTP auth";
71 push @$buttons, $button_text;
73 if ($form->submitted && $form->submitted eq $button_text) {
74 # bounce thru cgiauthurl and then back to
75 # the stored postsignin action
76 redir_cgiauthurl($cgi, do => "postsignin");
81 sub test_httpauth_pagespec ($) {
93 if (! defined $cgi->remote_user() &&
94 defined $config{httpauth_pagespec} &&
95 length $config{httpauth_pagespec} &&
96 defined $config{cgiauthurl} &&
97 pagespec_match($page, $config{httpauth_pagespec})) {
99 # bounce thru cgiauthurl and back to edit action
100 redir_cgiauthurl($cgi, $cgi->query_string());