1 package Catalyst::Authentication::Credential::FBConnect;
3 use MooseX::Types::Moose qw/ Bool /;
4 use MooseX::Types::Common::String qw/ NonEmptySimpleStr /;
5 use WWW::Facebook::API;
6 use Catalyst::Exception ();
7 use namespace::autoclean;
9 has debug => ( is => 'ro', isa => Bool, );
10 has api_key => ( is => 'ro', isa => NonEmptySimpleStr, required => 1 );
11 has secret => ( is => 'ro', isa => NonEmptySimpleStr, required => 1 );
12 has app_name => ( is => 'ro', isa => NonEmptySimpleStr, required => 1 );
13 has fbconnect => ( is => 'ro', lazy_build => 1, init_arg => undef, isa => 'WWW::Facebook::API' );
16 my ($class, $config, $c, $realm) = @_;
23 $self->fbconnect; # Ensure lazy value is built.
26 sub _build_fbconnect {
29 WWW::Facebook::API->new(
31 map { $_ => $self->$_() } qw/ app_name api_key secret /
36 my ($self, $c, $realm, $auth_info) = @_;
38 my $token = $c->req->method eq 'GET'
39 ? $c->req->query_params->{'auth_token'}
40 : $c->req->body_params->{'auth_token'};
42 if( defined $token ) {
44 $self->fbconnect->auth->get_session( $token );
47 session_uid => $self->fbconnect->session_uid,
48 session_key => $self->fbconnect->session_key,
49 session_expires => $self->fbconnect->session_expires
52 my $user_obj = $realm->find_user( $user, $c );
54 return $user_obj if ref $user_obj;
56 $c->log->debug( 'Verified FBConnect itentity failed' ) if $self->debug;
61 $c->res->redirect( $self->fbconnect->get_login_url( next => $c->uri_for( $c->action, $c->req->captures, @{ $c->req->args } ) ) );
72 Catalyst::Authentication::Credential::FBConnect - Facebook credential for Catalyst::Plugin::Authentication framework.
85 Session::Store::FastMmap
86 Session::State::Cookie
92 <Plugin::Authentication>
93 default_realm facebook
104 </Plugin::Authentication>
109 sub facebook : Local {
112 if( $c->authenticate() ) {
113 #do something with $c->user
123 =item $c->user->session_uid
125 =item $c->user->session_key
127 =item $c->user->session_expires
133 Cosmin Budrica E<lt>cosmin@sinapticode.comE<gt>
135 Bogdan Lucaciu E<lt>bogdan@sinapticode.comE<gt>
139 Copyright (c) 2009 Sinapticode. All rights reserved
141 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.