| 1 | package OAuth::Lite2::Server::GrantHandler::ClientCredentials; | ||||||||||||||||||||||||||||
| 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 | 6 | ▶ | my ($self, $dh) = @_; | ||||||||||||||||||||||||||
|
Subroutine
handle_request: called CC=11 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 6 | my $req = $dh->request; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 6 | my $parser = OAuth::Lite2::ParamMethod::AuthHeader->new; | |||||||||||||||||||||||||||
| 17 | 6 | my $header_credentials = $parser->basic_credentials($req); | |||||||||||||||||||||||||||
| 18 | 6 | ▶ | my $client_id = ($header_credentials->{client_id}) ? $header_credentials->{client_id} : $req->param("client_id"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 6 | ▶ | my $client_secret = ($header_credentials->{client_secret}) ? $header_credentials->{client_secret} : $req->param("client_secret"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 6 | my $user_id = $dh->get_client_user_id($client_id, $client_secret); | |||||||||||||||||||||||||||
| 22 | 6 | ▶ | OAuth::Lite2::Server::Error::InvalidClient->throw unless defined $user_id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 5 | my $scope = $req->param("scope"); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 5 | my $auth_info = $dh->create_or_update_auth_info( | |||||||||||||||||||||||||||
| 27 | client_id => $client_id, | ||||||||||||||||||||||||||||
| 28 | user_id => $user_id, | ||||||||||||||||||||||||||||
| 29 | scope => $scope, | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | 5 | ▶ | Carp::croak "OAuth::Lite2::Server::DataHandler::create_or_update_auth_info doesn't return OAuth::Lite2::Model::AuthInfo" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$auth_info and $auth_info->isa("OAuth::Lite2::Model::AuthInfo")
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")
| |||||||||||||||||||||||||||||
| 32 | unless ($auth_info | ||||||||||||||||||||||||||||
| 33 | && $auth_info->isa("OAuth::Lite2::Model::AuthInfo")); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 5 | my $access_token = $dh->create_or_update_access_token( | |||||||||||||||||||||||||||
| 36 | auth_info => $auth_info, | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | 5 | ▶ | Carp::croak "OAuth::Lite2::Server::DataHandler::create_or_update_access_token doesn't return OAuth::Lite2::Model::AccessToken" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$access_token and $access_token->isa("OAuth::Lite2::Model::AccessToken")
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")
| |||||||||||||||||||||||||||||
| 39 | unless ($access_token | ||||||||||||||||||||||||||||
| 40 | && $access_token->isa("OAuth::Lite2::Model::AccessToken")); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 5 | my $res = { | |||||||||||||||||||||||||||
| 43 | token_type => 'Bearer', | ||||||||||||||||||||||||||||
| 44 | access_token => $access_token->token, | ||||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||
| 46 | 5 | ▶ | $res->{expires_in} = $access_token->expires_in | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | if $access_token->expires_in; | ||||||||||||||||||||||||||||
| 48 | 5 | ▶ | $res->{refresh_token} = $auth_info->refresh_token | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | if $auth_info->refresh_token; | ||||||||||||||||||||||||||||
| 50 | 5 | ▶ | $res->{scope} = $auth_info->scope | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | if $auth_info->scope; | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 5 | return $res; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head1 NAME | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | OAuth::Lite2::Server::GrantHandler::ClientCredentials - handler for 'client_credentials' grant_type request | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | my $handler = OAuth::Lite2::Server::GrantHandler::ClientCredentials->new; | ||||||||||||||||||||||||||||
| 63 | my $res = $handler->handle_request( $data_handler ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | handler for 'client_credentials' grant_type request. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head1 METHODS | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =head2 handle_request( $req ) | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | See L<OAuth::Lite2::Server::GrantHandler> document. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Lyo Kato, E<lt>lyo.kato@gmail.comE<gt> | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Copyright (C) 2010 by Lyo Kato | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 84 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||||||||||||||||||||||||||||
| 85 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 8 | 1; | |||||||||||||||||||||||||||