[Catalyst-commits] r10951 - in Catalyst-Authentication-Credential-FBConnect/trunk: . lib lib/Catalyst lib/Catalyst/Authentication lib/Catalyst/Authentication/Credential t

zamolxes at dev.catalyst.perl.org zamolxes at dev.catalyst.perl.org
Wed Jul 22 22:48:27 GMT 2009


Author: zamolxes
Date: 2009-07-22 22:48:27 +0000 (Wed, 22 Jul 2009)
New Revision: 10951

Added:
   Catalyst-Authentication-Credential-FBConnect/trunk/Changes
   Catalyst-Authentication-Credential-FBConnect/trunk/MANIFEST.SKIP
   Catalyst-Authentication-Credential-FBConnect/trunk/Makefile.PL
   Catalyst-Authentication-Credential-FBConnect/trunk/README
   Catalyst-Authentication-Credential-FBConnect/trunk/lib/
   Catalyst-Authentication-Credential-FBConnect/trunk/lib/Catalyst/
   Catalyst-Authentication-Credential-FBConnect/trunk/lib/Catalyst/Authentication/
   Catalyst-Authentication-Credential-FBConnect/trunk/lib/Catalyst/Authentication/Credential/
   Catalyst-Authentication-Credential-FBConnect/trunk/lib/Catalyst/Authentication/Credential/FBConnect.pm
   Catalyst-Authentication-Credential-FBConnect/trunk/t/
   Catalyst-Authentication-Credential-FBConnect/trunk/t/00-load.t
Log:
initial upload


Added: Catalyst-Authentication-Credential-FBConnect/trunk/Changes
===================================================================
--- Catalyst-Authentication-Credential-FBConnect/trunk/Changes	                        (rev 0)
+++ Catalyst-Authentication-Credential-FBConnect/trunk/Changes	2009-07-22 22:48:27 UTC (rev 10951)
@@ -0,0 +1,5 @@
+Revision history for Catalyst::Authentication::Credential::FBConnect
+
+
+0.01 Tue July 08 17:17 2009
+	original version

Added: Catalyst-Authentication-Credential-FBConnect/trunk/MANIFEST.SKIP
===================================================================
--- Catalyst-Authentication-Credential-FBConnect/trunk/MANIFEST.SKIP	                        (rev 0)
+++ Catalyst-Authentication-Credential-FBConnect/trunk/MANIFEST.SKIP	2009-07-22 22:48:27 UTC (rev 10951)
@@ -0,0 +1,8 @@
+.git/
+blib
+pm_to_blib
+MANIFEST.bak
+MANIFEST.SKIP~
+cover_db
+Makefile$
+Makefile.old$

Added: Catalyst-Authentication-Credential-FBConnect/trunk/Makefile.PL
===================================================================
--- Catalyst-Authentication-Credential-FBConnect/trunk/Makefile.PL	                        (rev 0)
+++ Catalyst-Authentication-Credential-FBConnect/trunk/Makefile.PL	2009-07-22 22:48:27 UTC (rev 10951)
@@ -0,0 +1,14 @@
+use inc::Module::Install;
+
+name 'Catalyst-Authentication-Credential-FBConnect';
+all_from 'lib/Catalyst/Authentication/Credential/FBConnect.pm';
+
+requires 'WWW::Facebook::API';
+requires 'Moose';
+build_requires 'Catalyst::Runtime';
+build_requires 'Test::WWW::Mechanize::Catalyst';
+build_requires 'Test::More';
+build_requires 'ok';
+
+
+WriteAll();

Added: Catalyst-Authentication-Credential-FBConnect/trunk/README
===================================================================

Added: Catalyst-Authentication-Credential-FBConnect/trunk/lib/Catalyst/Authentication/Credential/FBConnect.pm
===================================================================
--- Catalyst-Authentication-Credential-FBConnect/trunk/lib/Catalyst/Authentication/Credential/FBConnect.pm	                        (rev 0)
+++ Catalyst-Authentication-Credential-FBConnect/trunk/lib/Catalyst/Authentication/Credential/FBConnect.pm	2009-07-22 22:48:27 UTC (rev 10951)
@@ -0,0 +1,152 @@
+package Catalyst::Authentication::Credential::FBConnect;
+use strict;
+use warnings;
+
+use Moose;
+
+has _config => ( is => 'rw' );
+has debug => ( is => 'rw' );
+has key => ( is => 'rw' );
+has secret => ( is => 'rw' );
+has app_name => ( is => 'rw' );
+has fbconnect => ( is => 'rw' );
+
+use WWW::Facebook::API;
+use Catalyst::Exception ();
+
+sub new {
+	my ($class, $config, $c, $realm) = @_;
+
+	my $self = { _config => {
+		%{ $config },
+		%{ $realm->{config} }
+	} };
+
+	bless $self, $class;
+
+	$self->debug( $self->_config->{debug} );
+
+	$self->key( $self->_config->{key} );
+	$self->secret( $self->_config->{secret} );
+	$self->app_name( $self->_config->{app_name} );
+
+	$self->fbconnect( WWW::Facebook::API->new(
+		desktop => 0,
+		app_name => $self->app_name,
+		api_key => $self->key,
+		secret => $self->secret
+	) );
+	
+	return $self;
+}
+
+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'};
+
+	if( defined $token ) {
+
+		$self->fbconnect->auth->get_session( $token );
+
+		my $user = +{
+			session_uid => $self->fbconnect->session_uid,
+			session_key => $self->fbconnect->session_key,
+			session_expires => $self->fbconnect->session_expires
+		};	
+
+		my $user_obj = $realm->find_user( $user, $c );
+		
+		return $user_obj if ref $user_obj;
+
+		$c->log->debug( 'Verified FBConnect itentity failed' ) if $self->debug;
+
+		return;
+	}
+	else {
+
+		$c->res->redirect( $self->fbconnect->get_login_url( next => $c->uri_for( $c->action ) ) );
+	}
+
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Catalyst::Authentication::Credential::FBConnect - Facebook credential for Catalyst::Plugin::Authentication framework.
+
+=head1 VERSION
+
+0.01
+
+=head1 SYNOPSIS
+
+In MyApp.pm
+
+ use Catalyst qw/
+      Authentication
+      Session
+      Session::Store::FastMmap
+      Session::State::Cookie
+ /;
+
+
+In myapp.conf
+
+ <Plugin::Authentication>
+      default_realm	facebook
+      <realms>
+           <facebook>
+                <credential>
+                     class	FBConnect
+		</credential>
+		key my_app_key
+                secret my_app_secret
+                app_name my_app_name
+           </facebook>
+      </realms>
+</Plugin::Authentication>
+
+
+In controller code,
+
+  sub facebook : Local {
+       my ($self, $c) = @_;
+
+       if( $c->authenticate() ) {
+             #do something with $c->user
+       }
+  }
+
+
+
+=head1 USER METHODS
+
+=over 4
+
+=item $c->user->session_uid
+
+=item $c->user->session_key
+
+=item $c->user->session_expires
+
+=back
+
+=head1 AUTHOR
+
+Cosmin Budrica E<lt>cosmin at sinapticode.comE<gt>
+
+Bogdan Lucaciu E<lt>bogdan at sinapticode.comE<gt>
+
+=head1 COPYRIGHT
+
+Copyright (c) 2009 Sinapticode. All rights reserved 
+
+This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
+
+=cut

Added: Catalyst-Authentication-Credential-FBConnect/trunk/t/00-load.t
===================================================================
--- Catalyst-Authentication-Credential-FBConnect/trunk/t/00-load.t	                        (rev 0)
+++ Catalyst-Authentication-Credential-FBConnect/trunk/t/00-load.t	2009-07-22 22:48:27 UTC (rev 10951)
@@ -0,0 +1,6 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More tests => 1;
+use ok 'Catalyst::Authentication::Credential::FBConnect';




More information about the Catalyst-commits mailing list