Version 9 of OpenID

Updated 2007-01-05 21:10:51

Zarutian 29. desember 2006 (UTC): I am not quite understanding the spec http://openid.net/specs/openid-authentication-1_1.html

Zarutian 00:00 29. desember 2006 (UTC): Starting of an OpenID consumer package

Zarutian 22:49 30. desember 2006 (UTC): I cant figure out why the regexp's dont work propperly.

 package require http
 proc geturl {url} {
   if {![regexp {^http://.*} $url]} { set url "http://[set url]" }
   set token [http::geturl $url]
   set ncode [http::ncode $token]
   if {($ncode == "301") || ($ncode == "302")} {
     # an redirect
     upvar #0 $token state
     if {![info exists state(meta)]} { error }
     array set meta $state(meta)
     if {![info exists meta(Location)]} { error }
     return [geturl $meta(Location)]
   }

   set data [http::data $token]  
   http::cleanup $token
   return $data
 }

 proc find_openid.server {input} {
   # <link rel="openid.server" href="http://openid.example.com/">
   if {[regexp {<link rel="openid.server" href="([^"]*)"} $input dummy server]} {
     return $server
   } else {
     return {}
   }
 }
 proc find_openid.delegate {input} {
   # <link rel="openid.delegate" href="http://exampleuser.livejournal.com/">
   if {[regexp {<link rel="openid.delegate" href="([^"]*)"} $input dummy delegate]} {
     return $delegate
   } else {
     return {}
   }
 }

 proc openid_checkid_immediate {url} {
   set stuff [geturl $url]

   set openid_server [find_openid.server $stuff]
   set openid_delegate [find_openid.delegate $stuff]
   puts "openid server = $openid_server"
   puts "openid delegate = $openid_delegate"

   if {[string match "*\?*" $openid_server]} {
     append openid_server "&"
   } else {
     append openid_server "?"
   }
   # not finished
 }

CJL - Which regexps are causing problems? I'm going to assume the first one is OK, but the ones in find_openid.server and find_openid.delegate aren't. Firstly, there's no need to match the text before and after the section of interest. Secondly '.*' is greedy - it will match as much as possible (i.e. it will match up to the LAST '>' in the input string, rather than just as far as the next one). To ask for the minimal match, use '.*?' instead, although I have found that doesn't always behave as I'd expect it to. In general, I'd say try to avoid the combination of '.*' if you can, and in this case it works if you match 'any number of non-quote characters'. In summary, I think your patterns should be more like:

   regexp {<link rel="openid.server" href="([^"]*)"} $input dummy server

Zarutian 21:02 5. januar 2006: Thank you, I am never entirely at ease with regexpes.