[OpenID] Complete method in Perl?

Amiri Barksdale amiribarksdale at gmail.com
Wed May 30 02:39:35 UTC 2007


Thanks for responding, David.

I am using JanRain!

Below you can see how I am setting the cookie, and it's content to be  
the id number of the session. So, the id of the session in the  
database is the cookie's value. I keep getting the error, "token not  
found in session," but I am passing the cookie, and the entire URL. I  
can see in my database, however, that there is a problem. Namely,  
during the first half of the operation, I get a full entry in the  
sessions table. I have the token key in there, type_uri, everything.  
But on the second part, when a second entry gets made in the session  
table, I have both an entirely new id, of course, because that's the  
primary key, but I have none of the other fields, especially no token  
field.

Here is how I constructed my consumer.
__________
<%init>
use strict;
use warnings;

use DBI;
use CGI;
use CGI::Session;
use Secret;
use Secret qw($name);
use Secret qw($pass);
use URI;
use URI::Query;
use URI::Escape;
use URI::QueryParam;
use Net::OpenID::JanRain::Consumer;
use Net::OpenID::JanRain::Stores::MySQLStore;

my $dbh = DBI->connect( "dbi:mysql:openid", $name, $pass ) || die  
$DBI::errstr;
my $cgi = new CGI;
my $session = CGI::Session->new( "driver:MySQL", $cgi, { Handle =>  
$dbh } );
my $cookie = $cgi->cookie( CGISESSID => $session->id );
my $store = Net::OpenID::JanRain::Stores::MySQLStore->new($dbh);

my $consumer = Net::OpenID::JanRain::Consumer->new( $session, $store );
my $complete;

if ($openid_url) {
     my $request = $consumer->begin($openid_url);

     if ( $request->status eq 'failure' ) {
         my $redirect5 = "/users/login_failed_all.html";
         $m->comp( "/generic/action/redirect.ml", url => $redirect5 );
	    }
     elsif ( $request->status eq 'success' || 'in_progress' ) {
         my $trust_root = "http://72.52.195.139/users";
         my $return_to  = "http://72.52.195.139/users/openid.html";
         $request->addExtensionArg( "sreg", "optional",
"nickname,email,fullname,dob,gender,postcode,country,language,timezone"
         );
         my $redirect = $request->redirectURL( $trust_root,  
$return_to );
         $m->comp( "/generic/action/redirect.ml", url => $redirect,  
cookie => $cookie );
	    }
	}
elsif ( $ARGS{'openid.mode'} ) {
	my $query  = URI::Query->new( $ENV{QUERY_STRING} );
	my %query  = $query->hash;
	$complete = $consumer->complete( \%query );

     if ( $complete->status eq 'success' ) {
         my $redirect1 = "/users/login_done.html";
         $m->comp( "/generic/action/redirect.ml", url => $redirect1 );
     	}
     elsif ( $complete->status eq 'failure' ) {
         my $redirect2 = "/users/completemessage.html";
         $m->comp( "/users/completemessage.html", complete =>  
$complete->message, cookie => $cookie );
     	}
     elsif ( $complete->status eq 'cancel' ) {
         my $redirect3 = "/users/login_canceled.html";
         $m->comp( "/generic/action/redirect.ml", url => $redirect3 );
     	}
     else {
         my $redirect4 = "/users/login_failed_some.html";
         $m->comp( "/generic/action/redirect.ml", url => $redirect4 );
     	}

}
</%init>
__________

Here is a pair of sample table entries:

| 93397c18efbc3cb8d3e0e2ccf3610544 | $D = {'_SESSION_ID' =>  
'93397c18efbc3cb8d3e0e2ccf3610544','_SESSION_ATIME' =>  
1180492307,'_openid_consumer_endpoints' => [bless( {'identity_url' =>  
bless( do{\(my $o = 'http://***.myopenid.com/')},  
'URI::http' ),'server_url' => 'http://www.myopenid.com/ 
server','delegate' => bless( do{\(my $o = 'http:// 
***.myopenid.com/')}, 'XML::XPath::Literal' ),'type_uris' => ['http:// 
openid.net/signon/1.0','http://openid.net/sreg/1.0']},  
'Net::OpenID::JanRain::Consumer::ServiceEndpoint' )],'_openid_consumer_t 
oken' =>  
'y4VqBfJiDE58NiOD5qZUcpnRIfoxMTgwNDkyMzA3AGh0dHA6Ly9hbWlyaWJhcmtzZGFsZS5 
teW9wZW5pZC5jb20vAGh0dHA6Ly9hbWlyaWJhcmtzZGFsZS5teW9wZW5pZC5jb20vAGh0dHA 
6Ly93d3cubXlvcGVuaWQuY29tL3NlcnZlcg==','_SESSION_REMOTE_ADDR' =>  
'***.***.***.***','_SESSION_CTIME' => 1180492307};;$D |

| fb7418d1dea9c95a6d5ca5afa41674c7 | $D = {'_SESSION_ID' =>  
'fb7418d1dea9c95a6d5ca5afa41674c7','_SESSION_ATIME' =>  
1180492319,'_SESSION_REMOTE_ADDR' =>  
'***.***.***.***','_SESSION_CTIME' => 1180492319};;$D


The disparity is glaring, and I can't figure out what I'm not passing  
through.

Amiri






On May 29, 2007, at 7:27 PM, Recordon, David wrote:

> Hi Amiri,
> What OpenID library for Perl are you using?
>
> --David
>
> From: general-bounces at openid.net [mailto:general- 
> bounces at openid.net] On Behalf Of Amiri Barksdale
> Sent: Tuesday, May 29, 2007 5:18 AM
> To: general at openid.net
> Subject: [OpenID] Complete method in Perl?
>
> I am having a dickens of a time finishing an openid login. I am  
> building a consumer in perl, and I am wondering if anyone knows why  
> this may not be working? I know I have a valid login, but I still  
> get a failure response. Here is the code for the completion:
>
>     my $query  = URI::Query->new( $ENV{QUERY_STRING} );
>     my %query  = $query->hash;
>     ...
>     my $complete = $consumer->complete( \%query );
>
>
> Here is what the IdP responds with before I try the above completion:
>
> openid.sreg.gender:    *
> openid.response_nonce:    2007-05-29T12:13:15Z8mrI9U
> openid.mode:    id_res
> openid.sreg.email:    ***@***.***
> openid.sreg.dob:    ****-**-**
> openid.assoc_handle:    {HMAC-SHA1}{4656da94}{mZCWxg==}
> openid.sreg.timezone:    America/***
> openid.op_endpoint:    http://www.myopenid.com/server
> openid.sreg.nickname:    ***
> openid.sreg.postcode:    *****
> openid.sreg.fullname:    ***
> openid.signed:     
> assoc_handle,identity,mode,op_endpoint,response_nonce,return_to,signed 
> ,sreg.country,sreg.dob,sreg.email,sreg.fullname,sreg.gender,sreg.langu 
> age,sreg.nickname,sreg.postcode,sreg.timezone
> openid.sig:    MkrfIgxaxRkFMo+CJI1amtpSLBY=
> openid.identity:    http://***.myopenid.com/
> nonce:    hvZi4DXd
> openid.sreg.language:    EN
> openid.return_to:    http://***.***.***.***/users/openid.html? 
> nonce=hvZi4DXd
> openid.sreg.country:    US
>
>
>
> Amiri

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openid.net/pipermail/openid-general/attachments/20070529/443c47ac/attachment-0002.htm>


More information about the general mailing list