[Catalyst-commits] r12731 -
Catalyst-Authentication-Credential-FBConnect/branches/fbconnect-fbjs/lib/Catalyst/Authentication/Credential
cosmincx at dev.catalyst.perl.org
cosmincx at dev.catalyst.perl.org
Tue Jan 26 19:22:14 GMT 2010
Author: cosmincx
Date: 2010-01-26 19:22:13 +0000 (Tue, 26 Jan 2010)
New Revision: 12731
Modified:
Catalyst-Authentication-Credential-FBConnect/branches/fbconnect-fbjs/lib/Catalyst/Authentication/Credential/FBConnect.pm
Log:
- added handling for fb params comming from js
- added "how" fb params come from js
todo:
- sane/the right way/etc checking
- pretty code
Modified: Catalyst-Authentication-Credential-FBConnect/branches/fbconnect-fbjs/lib/Catalyst/Authentication/Credential/FBConnect.pm
===================================================================
--- Catalyst-Authentication-Credential-FBConnect/branches/fbconnect-fbjs/lib/Catalyst/Authentication/Credential/FBConnect.pm 2010-01-26 18:40:30 UTC (rev 12730)
+++ Catalyst-Authentication-Credential-FBConnect/branches/fbconnect-fbjs/lib/Catalyst/Authentication/Credential/FBConnect.pm 2010-01-26 19:22:13 UTC (rev 12731)
@@ -35,9 +35,8 @@
sub authenticate {
my ($self, $c, $realm, $auth_info) = @_;
- my $token = $c->req->method eq 'GET'
- ? $c->req->query_params->{'auth_token'}
- : $c->req->body_params->{'auth_token'};
+ my $token = $c->req->param('auth_token');
+ my $sig = $c->req->param('fb_sig');
if( defined $token ) {
@@ -57,10 +56,35 @@
return;
}
- else {
- $c->res->redirect( $self->fbconnect->get_login_url( next => $c->uri_for( $c->action, $c->req->captures, @{ $c->req->args } ) ) );
- }
+ elsif( defined $sig ) {
+ my $fb_params = $self->fbconnect->canvas->get_fb_params( $c->req );
+ my $valid_sig = $self->fbconnect->verify_sig(
+ params => $fb_params,
+ sig => $sig,
+ );
+
+ if( $valid_sig ) {
+
+ my $user = +{
+ session_uid => $fb_params->{user},
+ session_key => $fb_params->{session_key},
+ session_expires => $fb_params->{expires}
+ };
+
+ my $user_obj = $realm->find_user( $user, $c);
+ return $user_obj if ref $user_obj;
+
+ $c->log_debug( 'Verified FBConnect identity failed' ) if $self->debug;
+ return;
+ }
+ }
+
+ $c->res->redirect(
+ $self->fbconnect->get_login_url(
+ next => $c->uri_for( $c->action, $c->req->captures, @{ $c->req->args } )
+ )
+ );
}
1;
@@ -114,8 +138,28 @@
}
}
+In your javascript, on a FBConnect button
+ FB.ensureInit( function() {
+ FB.Connect.requireSession( function() {
+ FB.Facebook.get_sessionState().waitUntilReady( function() {
+ var session = FB.Facebook.apiClient.get_session();
+ var url = '/auth/facebook' + '?fb_sig='+session['sig'];
+
+ for (var key in session) {
+ if( key != 'sig' )
+ url += '&' + 'fb_sig_' + key + '=' + session[key];
+ }
+
+ $.post( url, function() { location.href = "/"; } );
+ } );
+ } );
+ } );
+
+
+
+
=head1 USER METHODS
=over 4
More information about the Catalyst-commits
mailing list