File Coverage

blib/lib/Catalyst/ActionRole/OAuth2/RequestAuth.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 31 32 96.8


line stmt bran cond sub pod time code
1             package Catalyst::ActionRole::OAuth2::RequestAuth;
2 8     8   584565 use Moose::Role;
  8         25  
  8         96  
3 8     8   55652 use Try::Tiny;
  8         26  
  8         655  
4 8     8   403 use URI;
  8         31  
  8         240  
5 8     8   4721 use CatalystX::OAuth2::Request::RequestAuth;
  8         47  
  8         1970  
6              
7             # ABSTRACT: Authorization grant endpoint for OAuth2 authentication flows
8              
9              
10             with 'CatalystX::OAuth2::ActionRole::Grant';
11              
12             has enable_client_secret => ( isa => 'Bool', is => 'ro', default => 0 );
13              
14             sub build_oauth2_request {
15 8     8 0 33 my ( $self, $controller, $c ) = @_;
16              
17 8         351 my $store = $controller->store;
18 8         22 my $req;
19             try {
20             $req = CatalystX::OAuth2::Request::RequestAuth->new(
21 8     8   715 %{ $c->req->query_parameters } );
  8         33  
22 5         214 $req->enable_client_secret($self->enable_client_secret);
23 5         136 $req->store($store);
24             }
25             catch {
26 3     3   137630 $c->log->error($_);
27             # need to figure out a better way, but this will do for now
28 3         19545 $c->res->body(qq{warning: response_type/client_id invalid or missing});
29              
30 3         207 $c->detach;
31 8         110 };
32 5         102 return $req;
33             }
34              
35             1;
36              
37             __END__
38              
39             =pod
40              
41             =head1 NAME
42              
43             Catalyst::ActionRole::OAuth2::RequestAuth - Authorization grant endpoint for OAuth2 authentication flows
44              
45             =head1 VERSION
46              
47             version 0.001007
48              
49             =head1 SYNOPSIS
50              
51             package AuthServer::Controller::OAuth2::Provider;
52             use Moose;
53             BEGIN { extends 'Catalyst::Controller::ActionRole' }
54              
55             with 'CatalystX::OAuth2::Controller::Role::Provider';
56              
57             __PACKAGE__->config(
58             store => {
59             class => 'DBIC',
60             client_model => 'DB::Client'
61             }
62             );
63              
64             sub request : Chained('/') Args(0) Does('OAuth2::RequestAuth') {}
65              
66             =head1 DESCRIPTION
67              
68             This action role implements the initial endpoint that triggers the
69             authorization grant flow. It generates an inactive authorization code
70             redirects to the next action in the workflow if all parameters are valid. The
71             authorization code is used to verify the validity of the arguments in the
72             subsequent request of the flow and prevent users of this library from creating
73             potentially unsafe front-end forms for user confirmation of the authorization.
74              
75             =head1 AUTHOR
76              
77             Eden Cardim <edencardim@gmail.com>
78              
79             =head1 COPYRIGHT AND LICENSE
80              
81             This software is copyright (c) 2017 by Suretec Systems Ltd.
82              
83             This is free software; you can redistribute it and/or modify it under
84             the same terms as the Perl 5 programming language system itself.
85              
86             =cut