| 1 | package OAuth::Lite2::Server::GrantHandler::GroupingRefreshToken; | ||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use parent 'OAuth::Lite2::Server::GrantHandler'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
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 | |||||||||||||||||||||||||||||
| 10 | 10 | ▶ | sub handle_request { | ||||||||||||||||||||||||||
|
Subroutine
handle_request: called CC=17 SCAR=29.8
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 10 | my ($self, $dh) = @_; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 10 | my $req = $dh->request; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 10 | my $parser = OAuth::Lite2::ParamMethod::AuthHeader->new; | |||||||||||||||||||||||||||
| 16 | 10 | my $header_credentials = $parser->basic_credentials($req); | |||||||||||||||||||||||||||
| 17 | 10 | ▶ | my $client_id = ($header_credentials->{client_id}) ? $header_credentials->{client_id} : $req->param("client_id"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # validate grouping refresh_token | ||||||||||||||||||||||||||||
| 20 | 10 | ▶ | my $refresh_token = $req->param("refresh_token") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | or OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||
| 22 | description => "'refresh_token' not found" | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 9 | ▶ | my $grouping_auth_info = $dh->get_auth_info_by_refresh_token($refresh_token) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | or OAuth::Lite2::Server::Error::InvalidGrant->throw( | ||||||||||||||||||||||||||||
| 27 | description => "'refresh_token' is invalid" | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | 7 | ▶ | Carp::croak "OAuth::Lite2::Server::DataHandler::get_auth_info_by_refresh_token doesn't return OAuth::Lite2::Model::AuthInfo" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$grouping_auth_info and $grouping_auth_info->isa("OAuth::Lite2::Model::AuthInfo")
MC/DC0%0/2
$grouping_auth_info and $grouping_auth_info->isa("OAuth::Lite2::Model::AuthInfo")
$grouping_auth_info
$grouping_auth_info->isa("OAuth::Lite2::Model::AuthInfo")
Truth table33%1/3
A and B
A= $grouping_auth_infoB= $grouping_auth_info->isa("OAuth::Lite2::Model::AuthInfo")
| |||||||||||||||||||||||||||||
| 30 | unless ($grouping_auth_info | ||||||||||||||||||||||||||||
| 31 | && $grouping_auth_info->isa("OAuth::Lite2::Model::AuthInfo")); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 7 | ▶ | my $group_id = $dh->get_group_id_by_client_id( $grouping_auth_info->client_id ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | or OAuth::Lite2::Server::Error::InvalidGrant->throw( | ||||||||||||||||||||||||||||
| 35 | description => "'refresh_token' does not have group id" | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # validate target client | ||||||||||||||||||||||||||||
| 39 | 6 | ▶ | my $target_group_id = $dh->get_group_id_by_client_id( $client_id ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | or OAuth::Lite2::Server::Error::InvalidClient->throw( | ||||||||||||||||||||||||||||
| 41 | description => "'client_id' does not have group id" | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 5 | ▶ | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | description => "group id does not match" | ||||||||||||||||||||||||||||
| 46 | ) unless ( $group_id eq $target_group_id ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 4 | my $scope = $req->param("scope"); | |||||||||||||||||||||||||||
| 49 | 4 | ▶ | OAuth::Lite2::Server::Error::InvalidScope->throw | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | unless $dh->validate_grouping_scope( $client_id, $scope ); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # create response | ||||||||||||||||||||||||||||
| 53 | 3 | my $auth_info = $dh->create_or_update_auth_info( | |||||||||||||||||||||||||||
| 54 | client_id => $client_id, | ||||||||||||||||||||||||||||
| 55 | user_id => $grouping_auth_info->user_id, | ||||||||||||||||||||||||||||
| 56 | scope => $scope, | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | 3 | ▶ | 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")
| |||||||||||||||||||||||||||||
| 59 | unless ($auth_info | ||||||||||||||||||||||||||||
| 60 | && $auth_info->isa("OAuth::Lite2::Model::AuthInfo")); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 3 | my $access_token = $dh->create_or_update_access_token( | |||||||||||||||||||||||||||
| 63 | auth_info => $auth_info, | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | 3 | ▶ | 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")
| |||||||||||||||||||||||||||||
| 66 | unless ($access_token | ||||||||||||||||||||||||||||
| 67 | && $access_token->isa("OAuth::Lite2::Model::AccessToken")); | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 3 | my $res = { | |||||||||||||||||||||||||||
| 70 | token_type => 'Bearer', | ||||||||||||||||||||||||||||
| 71 | access_token => $access_token->token, | ||||||||||||||||||||||||||||
| 72 | }; | ||||||||||||||||||||||||||||
| 73 | 3 | ▶ | $res->{expires_in} = int($access_token->expires_in) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | if $access_token->expires_in; | ||||||||||||||||||||||||||||
| 75 | 3 | ▶ | $res->{refresh_token} = $auth_info->refresh_token | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | if $auth_info->refresh_token; | ||||||||||||||||||||||||||||
| 77 | 3 | ▶ | $res->{scope} = $auth_info->scope | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | if $auth_info->scope; | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | return $res; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 NAME | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | OAuth::Lite2::Server::GrantHandler::GroupingRefreshToken - handler for 'grouping-refresh-token' grant_type request | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | my $handler = OAuth::Lite2::Server::GrantHandler::GroupingRefreshToken->new; | ||||||||||||||||||||||||||||
| 90 | my $res = $handler->handle_request( $data_handler ); | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | handler for 'grouping-refresh-token' grant_type request. | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head1 METHODS | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head2 handle_request( $req ) | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | See L<OAuth::Lite2::Server::GrantHandler> document. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Lyo Kato, E<lt>lyo.kato@gmail.comE<gt> | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | Copyright (C) 2010 by Lyo Kato | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 111 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||||||||||||||||||||||||||||
| 112 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 8 | 1; | |||||||||||||||||||||||||||