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