Catalyst/ActionRole/OAuth2/GrantAuth.pm

filter: Statementstmt 86.9% 20 / 23 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 81.2% 26 / 32 SCAR 7.0
CC
2
Cov
84%
__ANON__
2.0
__ANON__
2.0
build_oauth2_request
1.0
CRAP 2.0
« CatalystX/OAuth2/Client.pm ↑ Summary CatalystX/OAuth2.pm »
1 package Catalyst::ActionRole::OAuth2::GrantAuth;
2 9 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use CatalystX::OAuth2::Request::GrantAuth;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Authorization grant endpoint for OAuth2 authentication flows
7  
8  
9 9 with 'CatalystX::OAuth2::ActionRole::Grant';
10  
11 sub build_oauth2_request {
12 12 ▶ my ( $self, $controller, $c ) = @_;
Subroutine build_oauth2_request: called CC=1 SCAR=0.2
Pod undocumented
13  
14 12 my $store = $controller->store;
15 12 my $req;
16 try {
17 $req = CatalystX::OAuth2::Request::GrantAuth->new(
18 12 ▶ %{ $c->req->query_parameters } );
Subroutine __ANON__: called CC=2 SCAR=7.0
19 12 $req->store($store);
20 12 ▶ $req->user($c->user) if $c->user_exists;
Branch: 1 branch
BranchTrueFalseTotal
if $c->user_exists 12 0 12
21 }
22 catch {
23 0 ▶ $c->log->error($_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
24  
25 # need to figure out a better way, but this will do for now
26 0 $c->res->body('warning: response_type/client_id invalid or missing');
27  
28 0 $c->detach;
29 12 };
30  
31 12 return $req;
32 }
33  
34 9 1;
35  
36 __END__
37  
38 =pod
39  
40 =head1 NAME
41  
42 Catalyst::ActionRole::OAuth2::GrantAuth - Authorization grant endpoint for OAuth2 authentication flows
43  
44 =head1 VERSION
45  
46 version 0.001006
47  
48 =head1 SYNOPSIS
49  
50 package AuthServer::Controller::OAuth2::Provider;
51 use Moose;
52 BEGIN { extends 'Catalyst::Controller::ActionRole' }
53  
54 with 'CatalystX::OAuth2::Controller::Role::Provider';
55  
56 __PACKAGE__->config(
57 store => {
58 class => 'DBIC',
59 client_model => 'DB::Client'
60 }
61 );
62  
63 sub grant : Chained('/') Args(0) Does('OAuth2::GrantAuth') {
64 my ( $self, $c ) = @_;
65  
66 my $oauth2 = $c->req->oauth2;
67  
68 $c->user_exists and $oauth2->user_is_valid(1)
69 or $c->detach('/passthrulogin');
70 }
71  
72 =head1 DESCRIPTION
73  
74 This action role implements the authorization confirmation endpoint that asks
75 the user if he wishes to grant resource access to the client. This is
76 generally done by presenting a form to the user. Regardless of the mechanism
77 used for this confirmation, the C<$c->req->oauth2> object must be informed of
78 the user's decision via the C<user_is_valid> attribute, which must be true by
79 the end of the request, in order for the authorization flow to be continued.
80  
81 =head1 AUTHOR
82  
83 Eden Cardim <edencardim@gmail.com>
84  
85 =head1 COPYRIGHT AND LICENSE
86  
87 This software is copyright (c) 2017 by Suretec Systems Ltd.
88  
89 This is free software; you can redistribute it and/or modify it under
90 the same terms as the Perl 5 programming language system itself.
91  
92 =cut
« CatalystX/OAuth2/Client.pm ↑ Summary CatalystX/OAuth2.pm »