line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Authentication::Credential::FBConnect; |
2
|
1
|
|
|
1
|
|
34265
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
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; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has debug => ( is => 'ro', isa => Bool, ); |
12
|
|
|
|
|
|
|
has api_key => ( is => 'ro', isa => NonEmptySimpleStr, required => 1 ); |
13
|
|
|
|
|
|
|
has secret => ( is => 'ro', isa => NonEmptySimpleStr, required => 1 ); |
14
|
|
|
|
|
|
|
has app_name => ( is => 'ro', isa => NonEmptySimpleStr, required => 1 ); |
15
|
|
|
|
|
|
|
has fbconnect => ( is => 'ro', lazy_build => 1, init_arg => undef, isa => 'WWW::Facebook::API' ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub BUILDARGS { |
18
|
|
|
|
|
|
|
my ($class, $config, $c, $realm) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
return $config; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub BUILD { |
24
|
|
|
|
|
|
|
my ($self) = @_; |
25
|
|
|
|
|
|
|
$self->fbconnect; # Ensure lazy value is built. |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _build_fbconnect { |
29
|
|
|
|
|
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
WWW::Facebook::API->new( |
32
|
|
|
|
|
|
|
desktop => 0, |
33
|
|
|
|
|
|
|
map { $_ => $self->$_() } qw/ app_name api_key secret / |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub authenticate { |
38
|
|
|
|
|
|
|
my ($self, $c, $realm, $auth_info) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $token = $c->req->method eq 'GET' |
41
|
|
|
|
|
|
|
? $c->req->query_params->{'auth_token'} |
42
|
|
|
|
|
|
|
: $c->req->body_params->{'auth_token'}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
if( defined $token ) { |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->fbconnect->auth->get_session( $token ); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $user = +{ |
49
|
|
|
|
|
|
|
session_uid => $self->fbconnect->session_uid, |
50
|
|
|
|
|
|
|
session_key => $self->fbconnect->session_key, |
51
|
|
|
|
|
|
|
session_expires => $self->fbconnect->session_expires |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $user_obj = $realm->find_user( $user, $c ); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
return $user_obj if ref $user_obj; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$c->log->debug( 'Verified FBConnect itentity failed' ) if $self->debug; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
|
|
|
|
|
|
$c->res->redirect( $self->fbconnect->get_login_url( next => $c->uri_for( $c->action, $c->req->captures, @{ $c->req->args } ) ) ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 NAME |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Catalyst::Authentication::Credential::FBConnect - Facebook credential for Catalyst::Plugin::Authentication framework. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 VERSION |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
0.01 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SYNOPSIS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
In MyApp.pm |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
use Catalyst qw/ |
85
|
|
|
|
|
|
|
Authentication |
86
|
|
|
|
|
|
|
Session |
87
|
|
|
|
|
|
|
Session::Store::FastMmap |
88
|
|
|
|
|
|
|
Session::State::Cookie |
89
|
|
|
|
|
|
|
/; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
In myapp.conf |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
<Plugin::Authentication> |
95
|
|
|
|
|
|
|
default_realm facebook |
96
|
|
|
|
|
|
|
<realms> |
97
|
|
|
|
|
|
|
<facebook> |
98
|
|
|
|
|
|
|
<credential> |
99
|
|
|
|
|
|
|
class FBConnect |
100
|
|
|
|
|
|
|
api_key my_app_key |
101
|
|
|
|
|
|
|
secret my_app_secret |
102
|
|
|
|
|
|
|
app_name my_app_name |
103
|
|
|
|
|
|
|
</credential> |
104
|
|
|
|
|
|
|
</facebook> |
105
|
|
|
|
|
|
|
</realms> |
106
|
|
|
|
|
|
|
</Plugin::Authentication> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
In controller code, |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub facebook : Local { |
112
|
|
|
|
|
|
|
my ($self, $c) = @_; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
if( $c->authenticate() ) { |
115
|
|
|
|
|
|
|
#do something with $c->user |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 USER METHODS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=over 4 |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item $c->user->session_uid |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item $c->user->session_key |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item $c->user->session_expires |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 AUTHOR |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Cosmin Budrica E<lt>cosmin@sinapticode.comE<gt> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Bogdan Lucaciu E<lt>bogdan@sinapticode.comE<gt> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
With contributions from: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Tomas Doran E<lt>bobtfish@bobtfish.netE</gt> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 COPYRIGHT |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Copyright (c) 2009 Sinapticode. All rights reserved |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |