3 package IkiWiki::Plugin::openid;
10 hook(type => "checkconfig", id => "smiley", call => \&checkconfig);
11 hook(type => "auth", id => "skeleton", call => \&auth);
14 sub checkconfig () { #{{{
15 # Currently part of the OpenID code is in CGI.pm, and is enabled by
17 # TODO: modularise it all out into this plugin..
25 if (defined $q->param('openid.mode')) {
26 my $csr=getobj($q, $session);
28 if (my $setup_url = $csr->user_setup_url) {
29 IkiWiki::redirect($q, $setup_url);
31 elsif ($csr->user_cancel) {
32 IkiWiki::redirect($q, $config{url});
34 elsif (my $vident = $csr->verified_identity) {
35 $session->param(name => $vident->url);
40 sub validate ($$$$) { #{{{
46 my $csr=getobj($q, $session);
48 my $claimed_identity = $csr->claimed_identity($openid_url);
49 if (! $claimed_identity) {
50 # Put the error in the form and fail validation.
51 $form->field(name => "openid_url", comment => $csr->err);
54 my $check_url = $claimed_identity->check_url(
55 return_to => IkiWiki::cgiurl(
56 do => $form->field("do"),
57 page => $form->field("page"),
58 title => $form->field("title"),
59 from => $form->field("from"),
60 subpage => $form->field("subpage")
62 trust_root => $config{cgiurl},
65 # Redirect the user to the OpenID server, which will
66 # eventually bounce them back to auth() above.
67 IkiWiki::redirect($q, $check_url);
71 sub getobj ($$) { #{{{
75 eval q{use Net::OpenID::Consumer};
79 eval q{use LWPx::ParanoidAgent};
81 $ua=LWPx::ParanoidAgent->new;
84 $ua=LWP::UserAgent->new;
87 # Store the secret in the session.
88 my $secret=$session->param("openid_secret");
89 if (! defined $secret) {
90 $secret=$session->param(openid_secret => time);
93 return Net::OpenID::Consumer->new(
96 consumer_secret => $secret,
97 required_root => $config{cgiurl},