line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OAuth::Lite2::Server::GrantHandler::AuthorizationCode; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1467
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
44
|
|
4
|
2
|
|
|
2
|
|
5
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
40
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
5
|
use parent 'OAuth::Lite2::Server::GrantHandler'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
8
|
|
7
|
2
|
|
|
2
|
|
62
|
use OAuth::Lite2::Server::Error; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
26
|
|
8
|
2
|
|
|
2
|
|
349
|
use OAuth::Lite2::ParamMethod::AuthHeader; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
37
|
|
9
|
2
|
|
|
2
|
|
8
|
use Carp (); |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
485
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub handle_request { |
12
|
10
|
|
|
10
|
1
|
304
|
my ($self, $dh) = @_; |
13
|
|
|
|
|
|
|
|
14
|
10
|
|
|
|
|
25
|
my $req = $dh->request; |
15
|
|
|
|
|
|
|
|
16
|
10
|
|
|
|
|
38
|
my $parser = OAuth::Lite2::ParamMethod::AuthHeader->new; |
17
|
10
|
|
|
|
|
23
|
my $header_credentials = $parser->basic_credentials($req); |
18
|
10
|
50
|
|
|
|
30
|
my $client_id = ($header_credentials->{client_id}) ? $header_credentials->{client_id} : $req->param("client_id"); |
19
|
|
|
|
|
|
|
|
20
|
10
|
100
|
|
|
|
1669
|
my $code = $req->param("code") |
21
|
|
|
|
|
|
|
or OAuth::Lite2::Server::Error::InvalidRequest->throw( |
22
|
|
|
|
|
|
|
description => "'code' not found" |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
9
|
100
|
|
|
|
72
|
my $redirect_uri = $req->param("redirect_uri") |
26
|
|
|
|
|
|
|
or OAuth::Lite2::Server::Error::InvalidRequest->throw( |
27
|
|
|
|
|
|
|
description => "'redirect_uri' not found" |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
8
|
|
|
|
|
52
|
my $server_state = $req->param("server_state"); |
31
|
|
|
|
|
|
|
|
32
|
8
|
100
|
|
|
|
50
|
my $auth_info = $dh->get_auth_info_by_code($code) |
33
|
|
|
|
|
|
|
or OAuth::Lite2::Server::Error::InvalidGrant->throw; |
34
|
|
|
|
|
|
|
|
35
|
7
|
50
|
33
|
|
|
132
|
Carp::croak "OAuth::Lite2::Server::DataHandler::get_auth_info_by_code doesn't return OAuth::Lite2::Model::AuthInfo" |
36
|
|
|
|
|
|
|
unless ($auth_info |
37
|
|
|
|
|
|
|
&& $auth_info->isa("OAuth::Lite2::Model::AuthInfo")); |
38
|
|
|
|
|
|
|
|
39
|
7
|
100
|
|
|
|
14
|
OAuth::Lite2::Server::Error::InvalidClient->throw |
40
|
|
|
|
|
|
|
unless ($auth_info->client_id eq $client_id); |
41
|
|
|
|
|
|
|
|
42
|
6
|
100
|
66
|
|
|
29
|
OAuth::Lite2::Server::Error::RedirectURIMismatch->throw |
43
|
|
|
|
|
|
|
unless ( $auth_info->redirect_uri |
44
|
|
|
|
|
|
|
&& $auth_info->redirect_uri eq $redirect_uri); |
45
|
|
|
|
|
|
|
|
46
|
5
|
100
|
|
|
|
41
|
if ( $auth_info->server_state ) { |
47
|
3
|
100
|
100
|
|
|
29
|
OAuth::Lite2::Server::Error::InvalidServerState->throw |
48
|
|
|
|
|
|
|
unless ( $server_state and $server_state eq $auth_info->server_state ); |
49
|
|
|
|
|
|
|
} else { |
50
|
2
|
100
|
|
|
|
12
|
OAuth::Lite2::Server::Error::InvalidServerState->throw if ( $server_state ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
10
|
my $access_token = $dh->create_or_update_access_token( |
54
|
|
|
|
|
|
|
auth_info => $auth_info, |
55
|
|
|
|
|
|
|
); |
56
|
2
|
50
|
33
|
|
|
29
|
Carp::croak "OAuth::Lite2::Server::DataHandler::create_or_update_access_token doesn't return OAuth::Lite2::Model::AccessToken" |
57
|
|
|
|
|
|
|
unless ($access_token |
58
|
|
|
|
|
|
|
&& $access_token->isa("OAuth::Lite2::Model::AccessToken")); |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
6
|
my $res = { |
61
|
|
|
|
|
|
|
token_type => 'Bearer', |
62
|
|
|
|
|
|
|
access_token => $access_token->token, |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
|
65
|
2
|
50
|
|
|
|
11
|
$res->{expires_in} = int($access_token->expires_in) |
66
|
|
|
|
|
|
|
if $access_token->expires_in; |
67
|
2
|
50
|
|
|
|
16
|
$res->{refresh_token} = $auth_info->refresh_token |
68
|
|
|
|
|
|
|
if $auth_info->refresh_token; |
69
|
2
|
50
|
|
|
|
17
|
$res->{scope} = $auth_info->scope |
70
|
|
|
|
|
|
|
if $auth_info->scope; |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
16
|
return $res; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 NAME |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
OAuth::Lite2::Server::GrantHandler::AuthorizationCode - handler for 'authorization-code' grant_type request |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SYNOPSIS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $handler = OAuth::Lite2::Server::GrantHandler::AuthorizationCode->new; |
82
|
|
|
|
|
|
|
my $res = $handler->handle_request( $data_handler ); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 DESCRIPTION |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
handler for 'authorization-code' grant_type request. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 METHODS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 handle_request( $req ) |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
See L document. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 AUTHOR |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Ryo Ito, Eritou.06@gmail.comE |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Lyo Kato, Elyo.kato@gmail.comE |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Copyright (C) 2010 by Lyo Kato |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
105
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
106
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |