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 => "canedit", id => "httpauth", call => \&canedit,
14 hook(type => "formbuilder_setup", id => "httpauth",
15 call => \&formbuilder_setup);
26 example => "http://example.com/wiki/auth/ikiwiki.cgi",
27 description => "url to redirect to when authentication is needed",
33 sub redir_cgiauthurl ($$) {
37 IkiWiki::redirect($cgi, $config{cgiauthurl}.'?'.$params);
45 if (defined $cgi->remote_user()) {
46 $session->param("name", $cgi->remote_user());
55 if (! defined $cgi->remote_user() && defined $config{cgiauthurl}) {
56 return sub { redir_cgiauthurl($cgi, $cgi->query_string()) };
63 sub formbuilder_setup (@) {
66 my $form=$params{form};
67 my $session=$params{session};
69 my $buttons=$params{buttons};
71 if ($form->title eq "signin" &&
72 ! defined $cgi->remote_user() && defined $config{cgiauthurl}) {
73 my $button_text="Login with HTTP auth";
74 push @$buttons, $button_text;
76 if ($form->submitted && $form->submitted eq $button_text) {
77 redir_cgiauthurl($cgi, "do=postsignin");