1 package Catalyst::Authentication::Credential::FBConnect;
5 use Moose; # Moose gave you strict and warnings already
7 # This _config thing just isn't needed.. It's a throwback in the code you've
8 # cargo culted to the days when the auth credential used to be a plugin
10 has _config => ( is => 'rw' ); # Do these actually need to be rw??
11 has debug => ( is => 'rw' );
12 has key => ( is => 'rw' );
13 has secret => ( is => 'rw' );
14 has app_name => ( is => 'rw' );
15 has fbconnect => ( is => 'rw' );
17 use WWW::Facebook::API;
18 use Catalyst::Exception ();
20 sub new { # Writing your own ->new method makes Moose sad, implement BUILDARGS
22 my ($class, $config, $c, $realm) = @_;
24 my $self = { _config => {
26 %{ $realm->{config} } # Ewww, gross hack to steal the realms config too.
31 $self->debug( $self->_config->{debug} );
33 $self->key( $self->_config->{key} );
34 $self->secret( $self->_config->{secret} );
35 $self->app_name( $self->_config->{app_name} );
37 $self->fbconnect( WWW::Facebook::API->new(
39 app_name => $self->app_name,
40 api_key => $self->key,
41 secret => $self->secret
48 my ($self, $c, $realm, $auth_info) = @_;
50 my $token = $c->req->method eq 'GET'
51 ? $c->req->query_params->{'auth_token'}
52 : $c->req->body_params->{'auth_token'};
54 if( defined $token ) {
56 $self->fbconnect->auth->get_session( $token );
59 session_uid => $self->fbconnect->session_uid,
60 session_key => $self->fbconnect->session_key,
61 session_expires => $self->fbconnect->session_expires
64 my $user_obj = $realm->find_user( $user, $c );
66 return $user_obj if ref $user_obj;
68 $c->log->debug( 'Verified FBConnect itentity failed' ) if $self->debug;
74 $c->res->redirect( $self->fbconnect->get_login_url( next => $c->uri_for( $c->action ) ) );
85 Catalyst::Authentication::Credential::FBConnect - Facebook credential for Catalyst::Plugin::Authentication framework.
98 Session::Store::FastMmap
99 Session::State::Cookie
105 <Plugin::Authentication>
106 default_realm facebook
117 </Plugin::Authentication>
122 sub facebook : Local {
125 if( $c->authenticate() ) {
126 #do something with $c->user
136 =item $c->user->session_uid
138 =item $c->user->session_key
140 =item $c->user->session_expires
146 Cosmin Budrica E<lt>cosmin@sinapticode.comE<gt>
148 Bogdan Lucaciu E<lt>bogdan@sinapticode.comE<gt>
152 Copyright (c) 2009 Sinapticode. All rights reserved
154 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.