| 1 | package Catalyst::ActionRole::OAuth2::ProtectedResource; | ||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use CatalystX::OAuth2::Request::ProtectedResource; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Resource endpoint for OAuth2 authentication flows | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 9 | with 'CatalystX::OAuth2::ActionRole::RequestInjector'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | sub build_oauth2_request { | ||||||||||||||||||||||||||||
| 11 | 5 | ▶ | my ( $self, $controller, $c ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
build_oauth2_request: called CC=5 SCAR=18.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | my $auth = $c->req->header('Authorization') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | or $c->res->status(401), $c->detach; | ||||||||||||||||||||||||||||
| 15 | 3 | my ( $type, $token ) = split ' ', $auth; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | my $is_valid = defined($token) | ||||||||||||||||||||||||||
|
Condition33%1/3
defined $token && length $token
MC/DC0%0/2
defined $token && length $token
defined $token
length $token
Truth table33%1/3
A && B
A= defined $tokenB= length $token
| |||||||||||||||||||||||||||||
| 18 | && length($token); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | if ( $is_valid | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$is_valid and my $token_obj = $controller->store->verify_client_token($token)
MC/DC0%0/2
$is_valid and my $token_obj = $controller->store->verify_client_token($token)
$is_valid
my $token_obj = $controller->store->verify_client_token($token)
Truth table33%1/3
A and B
A= $is_validB= my $token_obj = $controller->store->verify_client_token($token)
| |||||||||||||||||||||||||||||
| 21 | and my $token_obj = $controller->store->verify_client_token($token) ) | ||||||||||||||||||||||||||||
| 22 | { | ||||||||||||||||||||||||||||
| 23 | 3 | return CatalystX::OAuth2::Request::ProtectedResource->new( | |||||||||||||||||||||||||||
| 24 | token => $token_obj ); | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | 0 | $c->res->status(401); | |||||||||||||||||||||||||||
| 27 | 0 | $c->detach; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 9 | 1; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | __END__ | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =pod | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head1 NAME | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | Catalyst::ActionRole::OAuth2::ProtectedResource - Resource endpoint for OAuth2 authentication flows | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head1 VERSION | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | version 0.001006 | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | package AuthServer::Controller::OAuth2::Resource; | ||||||||||||||||||||||||||||
| 47 | use Moose; | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | BEGIN { extends 'Catalyst::Controller::ActionRole' } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | with 'CatalystX::OAuth2::Controller::Role::WithStore'; | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | __PACKAGE__->config( | ||||||||||||||||||||||||||||
| 54 | store => { | ||||||||||||||||||||||||||||
| 55 | class => 'DBIC', | ||||||||||||||||||||||||||||
| 56 | client_model => 'DB::Client' | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub resource : Chained('/') Args(0) Does('OAuth2::ProtectedResource') { | ||||||||||||||||||||||||||||
| 61 | my ( $self, $c ) = @_; | ||||||||||||||||||||||||||||
| 62 | $c->res->body( 'my protected resource' ); | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | This action role implements an arbitrary resource endpoint to be protected by | ||||||||||||||||||||||||||||
| 68 | the authorization flow. Clients will only be able to access this resource if | ||||||||||||||||||||||||||||
| 69 | they provide a valid access token. The action body should be customized like a | ||||||||||||||||||||||||||||
| 70 | regular action. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Eden Cardim <edencardim@gmail.com> | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | This software is copyright (c) 2017 by Suretec Systems Ltd. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 81 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =cut | ||||||||||||||||||||||||||||