[Catalyst-commits] r7142 - /
Catalyst-Plugin-Authentication-Credential-Facebook
Catalyst-Plugin-Authentication-Credential-Facebook/0.01
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/Catalyst
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/Catalyst/Plugin
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/Catalyst/Plugin/Authentication
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/Catalyst/Plugin/Authentication/Credential
jshirley at dev.catalyst.perl.org
jshirley at dev.catalyst.perl.org
Mon Nov 19 17:57:02 GMT 2007
Author: jshirley
Date: 2007-11-19 17:57:01 +0000 (Mon, 19 Nov 2007)
New Revision: 7142
Added:
Catalyst-Plugin-Authentication-Credential-Facebook/
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/MANIFEST.SKIP
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/Makefile.PL
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/Catalyst/
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/Catalyst/Plugin/
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/Catalyst/Plugin/Authentication/
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/Catalyst/Plugin/Authentication/Credential/
Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/Catalyst/Plugin/Authentication/Credential/Facebook.pm
Log:
First functional idea for the facebook credential, with auto-create hard coded (icky icky)
Added: Catalyst-Plugin-Authentication-Credential-Facebook/0.01/MANIFEST.SKIP
===================================================================
--- Catalyst-Plugin-Authentication-Credential-Facebook/0.01/MANIFEST.SKIP (rev 0)
+++ Catalyst-Plugin-Authentication-Credential-Facebook/0.01/MANIFEST.SKIP 2007-11-19 17:57:01 UTC (rev 7142)
@@ -0,0 +1,41 @@
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+,v$
+\B\.svn\b
+
+# Avoid Makemaker generated and utility files.
+\bMakefile$
+\bblib
+\bMakeMaker-\d
+\bpm_to_blib$
+\bblibdirs$
+^MANIFEST\.SKIP$
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build
+
+# Avoid temp and backup files.
+~$
+\.tmp$
+\.old$
+\.bak$
+\#$
+\b\.#
+\.DS_Store$
+
+# Avoid Apache::Test files
+t/conf/apache_test_config.pm
+t/conf/extra.conf$
+t/conf/httpd.conf
+t/conf/mime.types
+t/htdocs
+t/logs
+t/var
+
+# No tarballs!
+\.gz$
+
+# Skip the roadmap
+lib/Catalyst/ROADMAP.pod
Added: Catalyst-Plugin-Authentication-Credential-Facebook/0.01/Makefile.PL
===================================================================
--- Catalyst-Plugin-Authentication-Credential-Facebook/0.01/Makefile.PL (rev 0)
+++ Catalyst-Plugin-Authentication-Credential-Facebook/0.01/Makefile.PL 2007-11-19 17:57:01 UTC (rev 7142)
@@ -0,0 +1,12 @@
+use inc::Module::Install;
+
+name 'Catalyst-Plugin-Authentication-Credential-Facebook';
+all_from 'lib/Catalyst/Plugin/Authentication/Credential/Facebook.pm';
+
+requires 'Catalyst' => '5.7';
+
+requires 'Catalyst::Plugin::Authentication' => '0.10';
+requires 'WWW::Facebook::API';
+
+auto_install;
+WriteAll;
Added: Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/Catalyst/Plugin/Authentication/Credential/Facebook.pm
===================================================================
--- Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/Catalyst/Plugin/Authentication/Credential/Facebook.pm (rev 0)
+++ Catalyst-Plugin-Authentication-Credential-Facebook/0.01/lib/Catalyst/Plugin/Authentication/Credential/Facebook.pm 2007-11-19 17:57:01 UTC (rev 7142)
@@ -0,0 +1,168 @@
+package Catalyst::Plugin::Authentication::Credential::Facebook;
+
+use strict;
+use warnings;
+
+use base qw/Class::Accessor::Fast/;
+__PACKAGE__->mk_accessors( qw/_config _fb/ );
+
+use Carp;
+use WWW::Facebook::API;
+
+=head1 NAME
+
+Catalyst::Plugin::Authentication::Credential::Facebook
+
+=head1 SYNOPSIS
+
+ MyApp->config({
+ authentication => {
+ default_realm => 'local',
+ realms => {
+ # Setup a local realm so facebook users can login directly
+ # on the site as well.
+ local => {
+ credential => {
+ class => 'Password',
+ password_field => 'secret',
+ password_type => 'hashed',
+ password_hash_type => 'SHA-1'
+ },
+ store => {
+ class => 'DBIx::Class',
+ user_class => 'Schema::Person::Identity',
+ id_field => 'ident',
+ }
+ },
+ # Add the facebook realm
+ facebook => {
+ credential => {
+ class => 'Facebook',
+ api_key => 'your-api-key-here',
+ secret => 'da-secret'
+ },
+ # Store the local map to your own account
+ store => {
+ class => 'DBIx::Class',
+ user_class => 'Schema::Person::Identity',
+ id_field => 'ident',
+ }
+ },
+ },
+ }
+ });
+
+=head1 DESCRIPTION
+
+RTFS.
+
+This was hackish when I wrote it, and still is.
+
+It makes some assumptions about the database schema that I couldn't quite
+workout a good way of configuring.
+
+YOU MUST LOOK AT THE AUTO-CREATE STUFF BELOW!!!
+
+=cut
+
+sub new {
+ my ( $class, $config, $app ) = @_;
+
+ croak "Unable to use Credential::Facebook without api_key"
+ unless defined $config->{api_key};
+ croak "Unable to use Credential::Facebook without secret"
+ unless defined $config->{secret};
+
+ my $self = bless {
+ _config => $config,
+ }, $class;
+
+ return $self;
+}
+
+sub facebook {
+ my ( $self, $c ) = @_;
+ unless ( $self->_fb ) {
+ my $config = $self->_config;
+ my $fb = WWW::Facebook::API->new(
+ api_key => $config->{api_key},
+ secret => $config->{secret},
+ desktop => 0
+ );
+ croak "Unable to create Facebook client"
+ unless $fb;
+ $self->_fb($fb);
+ }
+ return $self->_fb;
+}
+
+sub authenticate {
+ my ( $self, $c, $authstore, $authinfo ) = @_;
+
+ my $fb = $c->model('Facebook') || $self->facebook;
+
+ my $ident = $fb->canvas->get_user( $c->req );
+ my $fb_params = $fb->canvas->get_fb_params( $c->req );
+ if ( $fb_params->{session_key} ) {
+ $fb->session_key( $fb_params->{session_key} );
+ }
+
+ unless ( $ident ) {
+ if ( $fb_params->{added} eq 0 and $fb_params->{api_key} ) {
+ my $url = $fb->get_add_url;
+ $c->detach('/util/redirect', [ $url ]);
+ return;
+ }
+ }
+
+ $c->stash->{fb_params} = $fb_params;
+
+ my $userfindauthinfo = {%{$authinfo}};
+ $userfindauthinfo->{'provider'} = 'facebook';
+ $userfindauthinfo->{'ident'} = $ident;
+
+ my $user_obj = $authstore->find_user($userfindauthinfo, $c);
+
+ # FIXME: This needs to be a bit more not stupid.
+ # Auto-create the Person and Person::Identity records, then call
+ # find_user again
+ unless ( $user_obj ) {
+ my $result = $fb->users->get_info(
+ uids => [ $ident ],
+ fields => [ qw/first_name/ ]
+ );
+
+ unless ( $result ) {
+ $c->log->error("Unable to fetch FaceBook first_name for $ident");
+ return 0;
+ }
+ my $name = $result->[0]->{first_name};
+
+ $c->model('Schema')->schema->txn_do( sub {
+ my $person = $c->model('Schema::Person')
+ ->create( { display_name => $name } );
+ $person->identities->create({
+ provider => 'facebook',
+ ident => $ident,
+ secret => ''
+ });
+ } );
+ $user_obj = $authstore->find_user($userfindauthinfo, $c);
+ }
+ $c->session->{fb_params} = $fb_params if $user_obj;
+ return $user_obj;
+ #$c->log->_dump($user_obj);
+}
+
+=head1 AUTHOR
+
+J. Shirley <jshirley at cpan.org>
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
More information about the Catalyst-commits
mailing list