« blib/lib/OAuth/Lite2/ParamMethod/AuthHeader.pm
↑ Summary
blib/lib/OAuth/Lite2/Client/ClientCredentials.pm »
| 1 | package OAuth::Lite2::Server::GrantHandler::AuthorizationCode; | ||||||||||||||||||||||||||||
| 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 | 19 | ▶ | my ($self, $dh) = @_; | ||||||||||||||||||||||||||
|
Subroutine
handle_request: called CC=19 SCAR=30.2
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 19 | my $req = $dh->request; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 19 | my $parser = OAuth::Lite2::ParamMethod::AuthHeader->new; | |||||||||||||||||||||||||||
| 17 | 19 | my $header_credentials = $parser->basic_credentials($req); | |||||||||||||||||||||||||||
| 18 | 19 | ▶ | my $client_id = ($header_credentials->{client_id}) ? $header_credentials->{client_id} : $req->param("client_id"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 19 | ▶ | my $code = $req->param("code") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | or OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||
| 22 | description => "'code' not found" | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 18 | ▶ | my $redirect_uri = $req->param("redirect_uri") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | or OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||
| 27 | description => "'redirect_uri' not found" | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 17 | my $server_state = $req->param("server_state"); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 17 | ▶ | my $auth_info = $dh->get_auth_info_by_code($code) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | or OAuth::Lite2::Server::Error::InvalidGrant->throw; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 14 | ▶ | Carp::croak "OAuth::Lite2::Server::DataHandler::get_auth_info_by_code 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")
| |||||||||||||||||||||||||||||
| 36 | unless ($auth_info | ||||||||||||||||||||||||||||
| 37 | && $auth_info->isa("OAuth::Lite2::Model::AuthInfo")); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 14 | ▶ | OAuth::Lite2::Server::Error::InvalidClient->throw | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | unless ($auth_info->client_id eq $client_id); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 13 | ▶ | OAuth::Lite2::Server::Error::RedirectURIMismatch->throw | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$auth_info->redirect_uri and $auth_info->redirect_uri eq $redirect_uri
MC/DC50%1/2
$auth_info->redirect_uri and $auth_info->redirect_uri eq $redirect_uri
$auth_info->redirect_uri
$auth_info->redirect_uri eq $redirect_uri
Truth table66%2/3
A and B
A= $auth_info->redirect_uriB= $auth_info->redirect_uri eq $redirect_uri
| |||||||||||||||||||||||||||||
| 43 | unless ( $auth_info->redirect_uri | ||||||||||||||||||||||||||||
| 44 | && $auth_info->redirect_uri eq $redirect_uri); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 10 | ▶ | if ( $auth_info->server_state ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 6 | ▶ | OAuth::Lite2::Server::Error::InvalidServerState->throw | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$server_state and $server_state eq $auth_info->server_state
MC/DC100%2/2
$server_state and $server_state eq $auth_info->server_state
$server_state
$server_state eq $auth_info->server_state
Truth table100%3/3
A and B
A= $server_stateB= $server_state eq $auth_info->server_state
| |||||||||||||||||||||||||||||
| 48 | unless ( $server_state and $server_state eq $auth_info->server_state ); | ||||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||
| 50 | 4 | ▶ | OAuth::Lite2::Server::Error::InvalidServerState->throw if ( $server_state ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 5 | my $access_token = $dh->create_or_update_access_token( | |||||||||||||||||||||||||||
| 54 | auth_info => $auth_info, | ||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||
| 56 | 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")
| |||||||||||||||||||||||||||||
| 57 | unless ($access_token | ||||||||||||||||||||||||||||
| 58 | && $access_token->isa("OAuth::Lite2::Model::AccessToken")); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 5 | my $res = { | |||||||||||||||||||||||||||
| 61 | token_type => 'Bearer', | ||||||||||||||||||||||||||||
| 62 | access_token => $access_token->token, | ||||||||||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 5 | ▶ | $res->{expires_in} = $access_token->expires_in | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | if $access_token->expires_in; | ||||||||||||||||||||||||||||
| 67 | 5 | ▶ | $res->{refresh_token} = $auth_info->refresh_token | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | if $auth_info->refresh_token; | ||||||||||||||||||||||||||||
| 69 | 5 | ▶ | $res->{scope} = $auth_info->scope | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | if $auth_info->scope; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 5 | 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<OAuth::Lite2::Server::GrantHandler> document. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | Ryo Ito, E<lt>ritou.06@gmail.comE<gt> | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Lyo Kato, E<lt>lyo.kato@gmail.comE<gt> | ||||||||||||||||||||||||||||
| 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 | 8 | 1; | |||||||||||||||||||||||||||