3 package IkiWiki::Plugin::openid;
10 hook(type => "getopt", id => "openid", call => \&getopt);
11 hook(type => "checkconfig", id => "openid", call => \&checkconfig);
12 hook(type => "auth", id => "openid", call => \&auth);
16 eval q{use Getopt::Long};
18 Getopt::Long::Configure('pass_through');
19 GetOptions("openidsignup=s" => \$config{openidsignup});
22 sub checkconfig () { #{{{
23 # Currently part of the OpenID code is in CGI.pm, and is enabled by
25 # TODO: modularise it all out into this plugin..
33 if (defined $q->param('openid.mode')) {
34 my $csr=getobj($q, $session);
36 if (my $setup_url = $csr->user_setup_url) {
37 IkiWiki::redirect($q, $setup_url);
39 elsif ($csr->user_cancel) {
40 IkiWiki::redirect($q, $config{url});
42 elsif (my $vident = $csr->verified_identity) {
43 $session->param(name => $vident->url);
46 error("OpenID failure: ".$csr->err);
49 elsif (defined $q->param('openid_identifier')) {
50 validate($q, $session, $q->param('openid_identifier'));
54 sub validate ($$$;$) { #{{{
60 my $csr=getobj($q, $session);
62 my $claimed_identity = $csr->claimed_identity($openid_url);
63 if (! $claimed_identity) {
65 # Put the error in the form and fail validation.
66 $form->field(name => "openid_url", comment => $csr->err);
74 my $check_url = $claimed_identity->check_url(
75 return_to => IkiWiki::cgiurl(do => "postsignin"),
76 trust_root => $config{cgiurl},
79 # Redirect the user to the OpenID server, which will
80 # eventually bounce them back to auth() above.
81 IkiWiki::redirect($q, $check_url);
85 sub getobj ($$) { #{{{
89 eval q{use Net::OpenID::Consumer};
93 eval q{use LWPx::ParanoidAgent};
95 $ua=LWPx::ParanoidAgent->new;
98 $ua=LWP::UserAgent->new;
101 # Store the secret in the session.
102 my $secret=$session->param("openid_secret");
103 if (! defined $secret) {
104 $secret=$session->param(openid_secret => time);
107 return Net::OpenID::Consumer->new(
110 consumer_secret => $secret,
111 required_root => $config{cgiurl},