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   580017 use Moose::Role;
  8         25  
  8         89  
3 8     8   47288 use Try::Tiny;
  8         27  
  8         572  
4 8     8   312 use URI;
  8         23  
  8         194  
5 8     8   3985 use CatalystX::OAuth2::Request::RequestAuth;
  8         35  
  8         1759  
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 34 my ( $self, $controller, $c ) = @_;
16              
17 8         283 my $store = $controller->store;
18 8         20 my $req;
19             try {
20             $req = CatalystX::OAuth2::Request::RequestAuth->new(
21 8     8   724 %{ $c->req->query_parameters } );
  8         40  
22 5         233 $req->enable_client_secret($self->enable_client_secret);
23 5         181 $req->store($store);
24             }
25             catch {
26 3     3   139685 $c->log->error($_);
27             # need to figure out a better way, but this will do for now
28 3         22805 $c->res->body(qq{warning: response_type/client_id invalid or missing});
29              
30 3         208 $c->detach;
31 8         110 };
32 5         127 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.001006
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