line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Authentication::Credential::Flickr; |
2
|
1
|
|
|
1
|
|
22560
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
754
|
use Flickr::API; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use NEXT; |
6
|
|
|
|
|
|
|
use UNIVERSAL::require; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.01_03'; |
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 |
27
|
|
|
|
|
|
|
flickr => { |
28
|
|
|
|
|
|
|
key => 'your api_key', |
29
|
|
|
|
|
|
|
secret => 'your secret_key', |
30
|
|
|
|
|
|
|
perms => 'read', # or write or delete |
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, useing it's api. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 EXTENDED METHODS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 setup |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub setup { |
68
|
|
|
|
|
|
|
my $c = shift; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $config = $c->config->{authentication}->{flickr} ||= {}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$config->{flickr_object} ||= do { |
73
|
|
|
|
|
|
|
( $config->{user_class} |
74
|
|
|
|
|
|
|
||= "Catalyst::Plugin::Authentication::User::Hash" )->require; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $flickr = Flickr::API->new( |
77
|
|
|
|
|
|
|
{ key => $config->{key}, |
78
|
|
|
|
|
|
|
secret => $config->{secret}, |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$flickr; |
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$c->NEXT::setup(@_); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 METHODS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 authenticate_flickr_url |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub authenticate_flickr_url { |
95
|
|
|
|
|
|
|
my $c = shift; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $config = $c->config->{authentication}->{flickr}; |
98
|
|
|
|
|
|
|
my $perms = shift || $config->{perms}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return $config->{flickr_object}->request_auth_url($perms); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 authenticate_flickr |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub authenticate_flickr { |
108
|
|
|
|
|
|
|
my $c = shift; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $config = $c->config->{authentication}->{flickr}; |
111
|
|
|
|
|
|
|
my $flickr = $config->{flickr_object}; |
112
|
|
|
|
|
|
|
my $frob = $c->req->params->{frob} or return; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $api_response = $flickr->execute_method( 'flickr.auth.getToken', |
115
|
|
|
|
|
|
|
{ frob => $frob, } ); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
if ( $api_response->{success} ) { |
118
|
|
|
|
|
|
|
my $user = {}; |
119
|
|
|
|
|
|
|
my $content = $api_response->content; |
120
|
|
|
|
|
|
|
( $user->{token} ) = $content =~ m!<token>(.*?)</token>!; |
121
|
|
|
|
|
|
|
( $user->{perms} ) = $content =~ m!<perms>(.*?)</perms>!; |
122
|
|
|
|
|
|
|
( $user->{nsid} ) = $content =~ m!nsid="(.*?)"!; |
123
|
|
|
|
|
|
|
( $user->{username} ) = $content =~ m!username="(.*?)"!; |
124
|
|
|
|
|
|
|
( $user->{fullname} ) = $content =~ m!fullname="(.*?)"!; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$c->log->debug("Successfully authenticated user '$user->{username}'.") |
127
|
|
|
|
|
|
|
if $c->debug; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $store = $config->{store} || $c->default_auth_store; |
130
|
|
|
|
|
|
|
if ( $store |
131
|
|
|
|
|
|
|
and my $store_user |
132
|
|
|
|
|
|
|
= $store->get_user( $user->{username}, $user ) ) |
133
|
|
|
|
|
|
|
{ |
134
|
|
|
|
|
|
|
$c->set_authenticated($store_user); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
else { |
137
|
|
|
|
|
|
|
$user = $config->{user_class}->new($user); |
138
|
|
|
|
|
|
|
$c->set_authenticated($user); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
return 1; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
else { |
144
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
return; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 AUTHOR |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Daisuke Murase E<lt>typester@cpan.orgE<gt> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 COPYRIGHT |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This program is free software; you can redistribute |
163
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
The full text of the license can be found in the |
166
|
|
|
|
|
|
|
LICENSE file included with this module. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |