line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Authentication::Credential::Flickr; |
2
|
1
|
|
|
1
|
|
66858
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
914
|
use Flickr::API; |
|
1
|
|
|
|
|
237088
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
1394
|
use NEXT; |
|
1
|
|
|
|
|
5160
|
|
|
1
|
|
|
|
|
36
|
|
6
|
1
|
|
|
1
|
|
2310
|
use UNIVERSAL::require; |
|
1
|
|
|
|
|
6685
|
|
|
1
|
|
|
|
|
14
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Catalyst::Plugin::Authentication::Credential::Flickr - Flickr authentication for Catalyst |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Catalyst qw/ |
17
|
|
|
|
|
|
|
Authentication |
18
|
|
|
|
|
|
|
Authentication::Credential::Flickr |
19
|
|
|
|
|
|
|
Session |
20
|
|
|
|
|
|
|
Session::Store::FastMmap |
21
|
|
|
|
|
|
|
Session::State::Cookie |
22
|
|
|
|
|
|
|
/; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
MyApp->config( |
25
|
|
|
|
|
|
|
authentication => { |
26
|
|
|
|
|
|
|
use_session => 1, # default 1. see C::P::Authentication |
27
|
|
|
|
|
|
|
flickr => { |
28
|
|
|
|
|
|
|
key => 'your api_key', |
29
|
|
|
|
|
|
|
secret => 'your secret_key', |
30
|
|
|
|
|
|
|
perms => 'read', # or write |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub default : Private { |
36
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if ( $c->user_exists ) { |
39
|
|
|
|
|
|
|
# $c->user setted |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# redirect flickr's login form |
44
|
|
|
|
|
|
|
sub login : Local { |
45
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
46
|
|
|
|
|
|
|
$c->res->redirect( $c->authenticate_flickr_url ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# login callback url |
50
|
|
|
|
|
|
|
sub auth : Path('/flickr') { |
51
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
52
|
|
|
|
|
|
|
if ( $c->authenticate_flickr ) { |
53
|
|
|
|
|
|
|
$c->res->redirect( $c->uri_for('/') ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This module provide authentication via Flickr, using it's api. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 EXTENDED METHODS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 setup |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub setup { |
68
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
0
|
|
|
|
my $config = $c->config->{authentication}->{flickr} ||= {}; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
0
|
|
|
|
$config->{flickr_object} ||= do { |
73
|
0
|
|
0
|
|
|
|
( $config->{user_class} |
74
|
|
|
|
|
|
|
||= "Catalyst::Plugin::Authentication::User::Hash" )->require; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $flickr = Flickr::API->new( |
77
|
|
|
|
|
|
|
{ key => $config->{key}, |
78
|
|
|
|
|
|
|
secret => $config->{secret}, |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$flickr; |
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$c->NEXT::setup(@_); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 METHODS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 authenticate_flickr_url |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub authenticate_flickr_url { |
95
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $config = $c->config->{authentication}->{flickr}; |
98
|
0
|
|
0
|
|
|
|
my $perms = shift || $config->{perms}; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $config->{flickr_object}->request_auth_url($perms); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 authenticate_flickr |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub authenticate_flickr { |
108
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $config = $c->config->{authentication}->{flickr}; |
111
|
0
|
|
|
|
|
|
my $flickr = $config->{flickr_object}; |
112
|
0
|
0
|
|
|
|
|
my $frob = $c->req->params->{frob} or return; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $api_response = $flickr->execute_method( 'flickr.auth.getToken', |
115
|
|
|
|
|
|
|
{ frob => $frob, } ); |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if ( $api_response->{success} ) { |
118
|
0
|
|
|
|
|
|
my $user = {}; |
119
|
0
|
|
|
|
|
|
my $content = $api_response->content; |
120
|
0
|
|
|
|
|
|
( $user->{token} ) = $content =~ m!<token>(.*?)</token>!; |
121
|
0
|
|
|
|
|
|
( $user->{perms} ) = $content =~ m!<perms>(.*?)</perms>!; |
122
|
0
|
|
|
|
|
|
( $user->{nsid} ) = $content =~ m!nsid="(.*?)"!; |
123
|
0
|
|
|
|
|
|
( $user->{username} ) = $content =~ m!username="(.*?)"!; |
124
|
0
|
|
|
|
|
|
( $user->{fullname} ) = $content =~ m!fullname="(.*?)"!; |
125
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
|
$c->log->debug("Successfully authenticated user '$user->{username}'.") |
127
|
|
|
|
|
|
|
if $c->debug; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
0
|
|
|
|
my $store = $config->{store} || $c->default_auth_store; |
130
|
0
|
0
|
0
|
|
|
|
if ( $store |
131
|
|
|
|
|
|
|
and my $store_user |
132
|
|
|
|
|
|
|
= $store->get_user( $user->{username}, $user ) ) |
133
|
|
|
|
|
|
|
{ |
134
|
0
|
|
|
|
|
|
$c->set_authenticated($store_user); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
else { |
137
|
0
|
|
|
|
|
|
$user = $config->{user_class}->new($user); |
138
|
0
|
|
|
|
|
|
$c->set_authenticated($user); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
return 1; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
else { |
144
|
0
|
0
|
|
|
|
|
$c->log->debug( |
145
|
|
|
|
|
|
|
sprintf |
146
|
|
|
|
|
|
|
"Failed to authenticate flickr. Error code: '%d', Reason: '%s'", |
147
|
|
|
|
|
|
|
$api_response->{error_code}, |
148
|
|
|
|
|
|
|
$api_response->{error_message}, |
149
|
|
|
|
|
|
|
) |
150
|
|
|
|
|
|
|
if $c->debug; |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 SEE ALSO |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L<Catalyst::Plugin::Authentication>, L<Catalyst::Plugin::Authentication::Credential::TypeKey> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 AUTHOR |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Daisuke Murase E<lt>typester@cpan.orgE<gt> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 COPYRIGHT |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This program is free software; you can redistribute |
167
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
The full text of the license can be found in the |
170
|
|
|
|
|
|
|
LICENSE file included with this module. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |