« Catalyst/Authentication/Credential/OAuth2.pm
↑ Summary
CatalystX/OAuth2/Controller/Role/WithStore.pm »
| 1 | package CatalystX::OAuth2::Request::RequestAuth; | ||||||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Role for the initial request in the oauth2 flow | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 10 | with 'CatalystX::OAuth2::Grant'; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 10 | has client_secret => | |||||||||||||||||||||||||||||||
| 9 | ( isa => 'Str', is => 'ro', predicate => 'has_client_secret' ); | ||||||||||||||||||||||||||||||||
| 10 | 10 | has enable_client_secret => ( isa => 'Bool', is => 'rw', default => 0 ); | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | around _params => sub { | ||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | my $orig = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 5 | return $orig->(@_), qw(client_secret) | |||||||||||||||||||||||||||||||
| 15 | 10 | }; | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | # cargo-culted, a small refactor of the action roles should remove the need to do this | ||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | sub has_approval { 1 } | ||||||||||||||||||||||||||||||
|
Subroutine
has_approval: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | sub _build_query_parameters { | ||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_build_query_parameters: called CC=7 SCAR=21.0
| |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | my %q = $self->has_state ? ( state => $self->state ) : (); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | $self->response_type eq 'code' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 26 | or return { | ||||||||||||||||||||||||||||||||
| 27 | error => 'unsuported_response_type', | ||||||||||||||||||||||||||||||||
| 28 | error_description => 'this server does not support "' | ||||||||||||||||||||||||||||||||
| 29 | . $self->response_type | ||||||||||||||||||||||||||||||||
| 30 | . "' as a method for obtaining an authorization code", | ||||||||||||||||||||||||||||||||
| 31 | %q | ||||||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 3 | $q{response_type} = $self->response_type; | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 3 | my $store = $self->store; | |||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | my $client = $store->find_client( $self->client_id ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | or return { | ||||||||||||||||||||||||||||||||
| 39 | error => 'unauthorized_client', | ||||||||||||||||||||||||||||||||
| 40 | error_description => 'the client identified by ' | ||||||||||||||||||||||||||||||||
| 41 | . $self->client_id | ||||||||||||||||||||||||||||||||
| 42 | . ' is not authorized to access this resource' | ||||||||||||||||||||||||||||||||
| 43 | }; | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 3 | ▶ | $store->verify_client_secret( $self->client_id, $self->client_secret ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$self->enable_client_secret && ($store->verify_client_secret($self->client_id, $self->client_secret) || (return {'error', 'unauthorized_client', 'error_description', 'the client identified by ' . $self->client_id . ' is not authorized to access this resource'}))
$store->verify_client_secret($self->client_id, $self->client_secret) or return {"error", "unauthorized_client", "error_description", 'the client identified by ' . $self->client_id . ' is not authorized to access this resource'}
MC/DC0%0/2
$self->enable_client_secret && ($store->verify_client_secret($self->client_id, $self->client_secret) || (return {'error', 'unauthorized_client', 'error_description', 'the client identified by ' . $self->client_id . ' is not authorized to access this resource'}))
$self->enable_client_secret
$store->verify_client_secret($self->client_id, $self->client_secret)
Truth table33%1/3
A && B
A= $self->enable_client_secretB= $store->verify_client_secret($self->client_id, $self->client_secret)
| |||||||||||||||||||||||||||||||||
| 46 | or return { | ||||||||||||||||||||||||||||||||
| 47 | error => 'unauthorized_client', | ||||||||||||||||||||||||||||||||
| 48 | error_description => 'the client identified by ' | ||||||||||||||||||||||||||||||||
| 49 | . $self->client_id | ||||||||||||||||||||||||||||||||
| 50 | . ' is not authorized to access this resource' | ||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | if $self->enable_client_secret; | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 3 | $q{client_id} = $self->client_id; | |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 3 | ▶ | $client->endpoint eq $self->redirect_uri | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 57 | or return { | ||||||||||||||||||||||||||||||||
| 58 | error => 'invalid_request', | ||||||||||||||||||||||||||||||||
| 59 | error_description => | ||||||||||||||||||||||||||||||||
| 60 | 'redirection_uri does not match the registered client endpoint' | ||||||||||||||||||||||||||||||||
| 61 | }; | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 3 | $q{redirect_uri} = $self->redirect_uri; | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 3 | my $code = $store->create_client_code( $self->client_id ); | |||||||||||||||||||||||||||||||
| 66 | 3 | $q{code} = $code->as_string; | |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 3 | return \%q; | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | sub next_action_uri { | ||||||||||||||||||||||||||||||||
| 72 | 7 | ▶ | my ( $self, $controller, $c ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
next_action_uri: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 73 | 7 | $c->uri_for( $controller->_get_auth_token_via_auth_grant_action, | |||||||||||||||||||||||||||||||
| 74 | $self->query_parameters ); | ||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 10 | 1; | |||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | =pod | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | CatalystX::OAuth2::Request::RequestAuth - Role for the initial request in the oauth2 flow | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | version 0.001006 | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | Eden Cardim <edencardim@gmail.com> | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | This software is copyright (c) 2017 by Suretec Systems Ltd. | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||
| 100 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||||||