blib/lib/OAuth/Lite2/Server/GrantHandler/Password.pm

filter: Statementstmt 100% 38 / 38 Branchbran 72.2% 13 / 18 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 82.4% 61 / 74 SCAR 25.2
CC
12
Cov
85%
handle_request
13.3
BEGIN
1.0
BEGIN
1.0
CRAP 12.4
« blib/lib/OAuth/Lite2/Client/UsernameAndPassword.pm ↑ Summary blib/lib/OAuth/Lite2/Server/GrantHandler/RefreshToken.pm »
1 package OAuth::Lite2::Server::GrantHandler::Password;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use parent 'OAuth::Lite2::Server::GrantHandler';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use OAuth::Lite2::Server::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use OAuth::Lite2::ParamMethod::AuthHeader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub handle_request {
12 11 ▶ my ($self, $dh) = @_;
Subroutine handle_request: called CC=12 SCAR=25.9
Pod documented
13  
14 11 my $req = $dh->request;
15  
16 11 my $parser = OAuth::Lite2::ParamMethod::AuthHeader->new;
17 11 my $header_credentials = $parser->basic_credentials($req);
18 11 ▶ my $client_id = ($header_credentials->{client_id}) ? $header_credentials->{client_id} : $req->param("client_id");
Branch: 1 branch
BranchTrueFalseTotal
$header_credentials->{'client_id'} ? : 3 8 11
19  
20 11 my $username = $req->param("username");
21 11 ▶ OAuth::Lite2::Server::Error::InvalidRequest->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $username 1 10 11
22 description => "'username' not found"
23 ) unless $username;
24  
25 10 ▶ my $password = $req->param("password")
Branch: 1 branch
BranchTrueFalseTotal
my $password = $req->param("password") or "OAuth::Lite2::Server::Error::InvalidRequest"->throw("description", "'password' not found") 1 9 10
26 or OAuth::Lite2::Server::Error::InvalidRequest->throw(
27 description => "'password' not found"
28 );
29  
30 9 ▶ my $user_id = $dh->get_user_id($username, $password)
Branch: 1 branch
BranchTrueFalseTotal
my $user_id = $dh->get_user_id($username, $password) or "OAuth::Lite2::Server::Error::InvalidGrant"->throw 6 3 9
31 or OAuth::Lite2::Server::Error::InvalidGrant->throw;
32  
33 3 my $scope = $req->param("scope");
34  
35 3 my $auth_info = $dh->create_or_update_auth_info(
36 client_id => $client_id,
37 user_id => $user_id,
38 scope => $scope,
39 );
40 3 ▶ Carp::croak "OAuth::Lite2::Server::DataHandler::create_or_update_auth_info doesn't return OAuth::Lite2::Model::AuthInfo"
Branch: 1 branch
BranchTrueFalseTotal
unless $auth_info and $auth_info->isa("OAuth::Lite2::Model::AuthInfo") 0 3 3
Condition33%1/3
$auth_info and $auth_info->isa("OAuth::Lite2::Model::AuthInfo")
!ll&&!rl&&r
003
MC/DC0%0/2
$auth_info and $auth_info->isa("OAuth::Lite2::Model::AuthInfo")
$auth_info $auth_info->isa("OAuth::Lite2::Model::AuthInfo")
Truth table33%1/3
A and B
A= $auth_infoB= $auth_info->isa("OAuth::Lite2::Model::AuthInfo")
ABresult
0X0
100
111
41 unless ($auth_info
42 && $auth_info->isa("OAuth::Lite2::Model::AuthInfo"));
43  
44 3 my $access_token = $dh->create_or_update_access_token(
45 auth_info => $auth_info,
46 );
47 3 ▶ Carp::croak "OAuth::Lite2::Server::DataHandler::create_or_update_access_token doesn't return OAuth::Lite2::Model::AccessToken"
Branch: 1 branch
BranchTrueFalseTotal
unless $access_token and $access_token->isa("OAuth::Lite2::Model::AccessToken") 0 3 3
Condition33%1/3
$access_token and $access_token->isa("OAuth::Lite2::Model::AccessToken")
!ll&&!rl&&r
003
MC/DC0%0/2
$access_token and $access_token->isa("OAuth::Lite2::Model::AccessToken")
$access_token $access_token->isa("OAuth::Lite2::Model::AccessToken")
Truth table33%1/3
A and B
A= $access_tokenB= $access_token->isa("OAuth::Lite2::Model::AccessToken")
ABresult
0X0
100
111
48 unless ($access_token
49 && $access_token->isa("OAuth::Lite2::Model::AccessToken"));
50  
51 3 my $res = {
52 token_type => 'Bearer',
53 access_token => $access_token->token,
54 };
55 3 ▶ $res->{expires_in} = $access_token->expires_in
Branch: 1 branch
BranchTrueFalseTotal
if $access_token->expires_in 3 0 3
56 if $access_token->expires_in;
57 3 ▶ $res->{refresh_token} = $auth_info->refresh_token
Branch: 1 branch
BranchTrueFalseTotal
if $auth_info->refresh_token 3 0 3
58 if $auth_info->refresh_token;
59 3 ▶ $res->{scope} = $auth_info->scope
Branch: 1 branch
BranchTrueFalseTotal
if $auth_info->scope 0 3 3
60 if $auth_info->scope;
61  
62 3 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<OAuth::Lite2::Server::GrantHandler> document.
83  
84 =head1 AUTHOR
85  
86 Lyo Kato, E<lt>lyo.kato@gmail.comE<gt>
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 8 1;
« blib/lib/OAuth/Lite2/Client/UsernameAndPassword.pm ↑ Summary blib/lib/OAuth/Lite2/Server/GrantHandler/RefreshToken.pm »