« blib/lib/OIDC/Lite/Server/AuthorizationHandler.pm
↑ Summary
blib/lib/Plack/Middleware/Auth/OIDC/ProtectedResource.pm »
| 1 | package OIDC::Lite::Server::GrantHandler::AuthorizationCode; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use parent 'OAuth::Lite2::Server::GrantHandler'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use OAuth::Lite2::Server::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use OAuth::Lite2::ParamMethod::AuthHeader; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | sub handle_request { | ||||||||||||||||||||||||||||
| 11 | 23 | ▶ | my ($self, $dh) = @_; | ||||||||||||||||||||||||||
|
Subroutine
handle_request: called CC=20 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 23 | my $req = $dh->request; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 23 | my $parser = OAuth::Lite2::ParamMethod::AuthHeader->new; | |||||||||||||||||||||||||||
| 16 | 23 | my $header_credentials = $parser->basic_credentials($req); | |||||||||||||||||||||||||||
| 17 | 23 | ▶ | my $client_id = ($header_credentials->{client_id}) ? $header_credentials->{client_id} : $req->param("client_id"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 23 | ▶ | my $code = $req->param("code") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | or OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||
| 21 | description => "'code' not found" | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 22 | ▶ | my $redirect_uri = $req->param("redirect_uri") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | or OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||
| 26 | description => "'redirect_uri' not found" | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 20 | my $server_state = $req->param("server_state"); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 20 | ▶ | my $auth_info = $dh->get_auth_info_by_code($code) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | or OAuth::Lite2::Server::Error::InvalidGrant->throw; | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 17 | ▶ | Carp::croak "OAuth::Lite2::Server::DataHandler::get_auth_info_by_code doesn't return OAuth::Lite2::Model::AuthInfo" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$auth_info and $auth_info->isa("OIDC::Lite::Model::AuthInfo")
MC/DC50%1/2
$auth_info and $auth_info->isa("OIDC::Lite::Model::AuthInfo")
$auth_info
$auth_info->isa("OIDC::Lite::Model::AuthInfo")
Truth table66%2/3
A and B
A= $auth_infoB= $auth_info->isa("OIDC::Lite::Model::AuthInfo")
| |||||||||||||||||||||||||||||
| 35 | unless ($auth_info | ||||||||||||||||||||||||||||
| 36 | && $auth_info->isa("OIDC::Lite::Model::AuthInfo")); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 16 | ▶ | OAuth::Lite2::Server::Error::InvalidClient->throw | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | unless ($auth_info->client_id eq $client_id); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 15 | ▶ | OAuth::Lite2::Server::Error::RedirectURIMismatch->throw | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$auth_info->redirect_uri and $auth_info->redirect_uri eq $redirect_uri
MC/DC100%2/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 table100%3/3
A and B
A= $auth_info->redirect_uriB= $auth_info->redirect_uri eq $redirect_uri
| |||||||||||||||||||||||||||||
| 42 | unless ( $auth_info->redirect_uri | ||||||||||||||||||||||||||||
| 43 | && $auth_info->redirect_uri eq $redirect_uri); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 11 | ▶ | if ( $auth_info->server_state ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 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
| |||||||||||||||||||||||||||||
| 47 | unless ( $server_state and $server_state eq $auth_info->server_state ); | ||||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||
| 49 | 5 | ▶ | OAuth::Lite2::Server::Error::InvalidServerState->throw if ( $server_state ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 7 | my $access_token = $dh->create_or_update_access_token( | |||||||||||||||||||||||||||
| 53 | auth_info => $auth_info, | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | 7 | ▶ | Carp::croak "OAuth::Lite2::Server::DataHandler::create_or_update_access_token doesn't return OAuth::Lite2::Model::AccessToken" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$access_token and $access_token->isa("OAuth::Lite2::Model::AccessToken")
MC/DC50%1/2
$access_token and $access_token->isa("OAuth::Lite2::Model::AccessToken")
$access_token
$access_token->isa("OAuth::Lite2::Model::AccessToken")
Truth table66%2/3
A and B
A= $access_tokenB= $access_token->isa("OAuth::Lite2::Model::AccessToken")
| |||||||||||||||||||||||||||||
| 56 | unless ($access_token | ||||||||||||||||||||||||||||
| 57 | && $access_token->isa("OAuth::Lite2::Model::AccessToken")); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 6 | my $res = { | |||||||||||||||||||||||||||
| 60 | token_type => 'Bearer', | ||||||||||||||||||||||||||||
| 61 | access_token => $access_token->token, | ||||||||||||||||||||||||||||
| 62 | }; | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 6 | ▶ | $res->{expires_in} = $access_token->expires_in | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | if $access_token->expires_in; | ||||||||||||||||||||||||||||
| 66 | 6 | ▶ | $res->{refresh_token} = $auth_info->refresh_token | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | if $auth_info->refresh_token; | ||||||||||||||||||||||||||||
| 68 | 6 | ▶ | $res->{scope} = $auth_info->scope | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | if $auth_info->scope; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # ID Token | ||||||||||||||||||||||||||||
| 72 | 6 | ▶ | $res->{id_token} = $auth_info->id_token | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | if $auth_info->id_token; | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 6 | return $res; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head1 NAME | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | OIDC::Lite::Server::GrantHandler::AuthorizationCode - handler for 'authorization-code' grant_type request | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | my $handler = OIDC::Lite::Server::GrantHandler::AuthorizationCode->new; | ||||||||||||||||||||||||||||
| 85 | my $res = $handler->handle_request( $data_handler ); | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | handler for 'authorization-code' grant_type request. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head1 METHODS | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head2 handle_request( $req ) | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | See L<OAuth::Lite2::Server::GrantHandler> document. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | Ryo Ito, E<lt>ritou.06@gmail.comE<gt> | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Copyright (C) 2012 by Ryo Ito | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 106 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||||||||||||||||||||||||||||
| 107 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 3 | 1; | |||||||||||||||||||||||||||