simple sample CGI code?

Dan Lyke danlyke at flutterby.com
Sat May 21 14:46:56 PDT 2005


Troy Benjegerdes writes:
> I took a quick look at the LJ example, but I was wondering if anyone has
> extracted (and posted somewhere) the minimal set of code to be an
> openid server that runs at something like
> 
> http://example.com/cgi-bin/openid.cgi 

I don't have time to hack on stuff this weekend, but here's the 15
minutes of doodling I did on Thursday or Friday.  If performance isn't
an issue, just add Nathan Bowen's command line stuff from a few
messages back where I've got the "INSERT CRYPTO STUFF HERE" note.

Dan

------- really gross code follows ----------------

#!/usr/bin/perl -w
use strict;
use CGI;
use LWP::Simple;

my $cgi = new CGI;

if (defined($cgi->param('login')))
  {
    my $r = get($cgi->param('openid'));
    if ($r && $r =~ /\<link\s+rel\=\"openid.server\"\s+href\=\"(.*?)\"\s*\/?\>/)
      {
        print $cgi->redirect($1.'?openid.return_to=http://danlyke.gamahuche.com/openid.cgi&openid.is_identity='.$cgi->param('openid'));
      }

  }
elsif (defined($cgi->param('openid.user_setup_url')))
  {
    print $cgi->redirect($cgi->param('openid.user_setup_url'));
  }
elsif (defined($cgi->param('openid.mode')))
  {
    print $cgi->header;
    print <<EOF;
<html>
<head>
  <title>OpenID results</title>
</head>
<body>
<h1>OpenID results</h1>
EOF

  print "INSERT THE CRYPTO CHECK STUFF IN HERE!<br>";

    foreach ($cgi->param())
      {
        print "<strong>$_</strong>".$cgi->param($_)."<br>\n";
	print O $cgi->param('openid.timestamp').'::assert_identity::'
          .$cgi->param('openid.assert_identity')
           .'::http://danlyke.gamahuche.com/openid.cgi<br>';
      }
print "</body></html>\n";
  }
else
{
  print $cgi->header();
  print <<EOF;
<html>
<head>
  <title>OpenID test</title>
</head>
<body>
  <h1>OpenID test</h1>
<form action="./openid.cgi" method="post">
  OpenID url: <input name="openid" type="text"> <input value="Login" type="submit" name="login">
</form>
</body>
</html>
EOF

  }




More information about the yadis mailing list