blib/lib/OAuth/Lite2/Server/Error.pm

filter: Statementstmt 97.0% 65 / 67 Branchbran n/a Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 95.1% 39 / 41 Podpod 0.0% 0 / 6 totaltotal 88.6% 109 / 123 SCAR 13.9
CC
4
Cov
95%
new
4.2
type
2.0
state
2.0
CRAP 4.0
« blib/lib/OAuth/Lite2/Server/GrantHandler/ServerState.pm ↑ Summary blib/lib/OAuth/Lite2/Formatters.pm »
1 package OAuth::Lite2::Server::Error;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 use overload
7 45 ▶ q{""} => sub { sprintf q{%s: %s}, $_[0]->type, $_[0]->description },
Subroutine __ANON__: called CC=1 SCAR=0.0
8 17 ▶ fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 OAuth::Lite2::Server::Error - OAuth 2.0 server errors
13  
14 =head1 SYNOPSIS
15  
16 # At End-User Endpoint
17  
18 try {
19  
20 if ($something_wrong) {
21  
22 OAuth::Lite2::Server::Error::InvalidRequest->throw(
23 description => q{Something wrong},
24 # state => q{foo},
25 );
26 }
27  
28 } catch {
29  
30 if ($_->isa("OAuth::Lite2::Server::Error")) {
31  
32 my $uri = URI->new( $client_callback_uri );
33  
34 my %error_params = ( error => $_->type );
35 $error_params{error_description} = $_->description if $_->description;
36 $error_params{state} = $_->state if $_->state;
37  
38 $uri->query_form(%error_params);
39  
40 $your_app->redirect( $uri->as_string );
41  
42 } else {
43  
44 # Internal Server Error
45  
46 }
47 };
48  
49  
50 # At token-endpoint
51  
52 try {
53  
54  
55 } catch {
56  
57 if ($_->isa("OAuth::Lite2::Server::Error")) {
58  
59 my %error_params = ( error => $_->type );
60 $error_params{error_description} = $_->description if $_->description;
61 $error_params{scope} = $_->scope if $_->scope;
62  
63 $req->new_response($_->code,
64 [ "Content-Type" => $formatter->type, "Cache-Control" => "no-store" ],
65 [ $formatter->format(\%error_params) ],
66 );
67  
68 } else {
69  
70 # rethrow
71 die $_;
72  
73 }
74  
75 };
76  
77 =head1 DESCRIPTION
78  
79 OAuth 2.0 error classes.
80  
81 See
82 L<http://tools.ietf.org/html/draft-ietf-oauth-v2-09>,
83 L<http://tools.ietf.org/html/rfc6749>,
84  
85 =head1 METHODS
86  
87 There are following errors
88  
89 =head1 ERRORS
90  
91 =over 4
92  
93 =item OAuth::Lite2::Server::Error::InvalidRequest
94  
95 =item OAuth::Lite2::Server::Error::InvalidClient
96  
97 =item OAuth::Lite2::Server::Error::UnauthorizedClient
98  
99 =item OAuth::Lite2::Server::Error::RedirectURIMismatch
100  
101 =item OAuth::Lite2::Server::Error::AccessDenied
102  
103 =item OAuth::Lite2::Server::Error::UnsupportedResponseType
104  
105 =item OAuth::Lite2::Server::Error::UnsupportedResourceType
106  
107 =item OAuth::Lite2::Server::Error::InvalidGrant
108  
109 =item OAuth::Lite2::Server::Error::UnsupportedGrantType
110  
111 =item OAuth::Lite2::Server::Error::InvalidScope
112  
113 =item OAuth::Lite2::Server::Error::InvalidToken
114  
115 =item OAuth::Lite2::Server::Error::ExpiredTokenLegacy
116  
117 =item OAuth::Lite2::Server::Error::ExpiredToken
118  
119 =item OAuth::Lite2::Server::Error::InsufficientScope
120  
121 =item OAuth::Lite2::Server::Error::InvalidServerState
122  
123 =item OAuth::Lite2::Server::Error::TemporarilyUnavailable
124  
125 =item OAuth::Lite2::Server::Error::ServerError
126  
127 =back
128  
129 =cut
130  
131 sub new {
132 106 ▶ my ($class, %args) = @_;
Subroutine new: called CC=4 SCAR=14.5
Pod undocumented
133 bless {
134 description => $args{description} || '',
135 state => $args{state} || '',
136 106 ▶ code => $args{code} || 400,
Condition66%4/6
$args{'description'} || ''
l!l
1294
$args{'state'} || ''
l!l
0106
$args{'code'} || 400
l!l
0106
MC/DC100%1/1
$args{'description'} || ''
$args{'description'}
MC/DC0%0/1
$args{'state'} || ''
$args{'state'}
MC/DC0%0/1
$args{'code'} || 400
$args{'code'}
Truth table100%2/2
A
A= $args{'description'}
Aresult
11
00
Truth table50%1/2
A
A= $args{'state'}
Aresult
11
00
Truth table50%1/2
A
A= $args{'code'}
Aresult
11
00
137 }, $class;
138 }
139  
140 sub throw {
141 89 ▶ my ($class, %args) = @_;
Subroutine throw: called CC=1 SCAR=0.0
Pod undocumented
142 89 die $class->new(%args);
143 }
144  
145 10 ▶sub code { $_[0]->{code} }
Subroutine code: called CC=1 SCAR=0.0
Pod undocumented
146 0 ▶sub type { die "abstract method" }
Subroutine type: not called CC=1 SCAR=6.9
Pod undocumented
147 103 ▶sub description { $_[0]->{description} }
Subroutine description: called CC=1 SCAR=0.0
Pod undocumented
148 0 ▶sub state { $_[0]->{state} }
Subroutine state: not called CC=1 SCAR=6.9
Pod undocumented
149  
150 # OAuth Server Error
151 package OAuth::Lite2::Server::Error::InvalidRequest;
152 17 our @ISA = qw(OAuth::Lite2::Server::Error);
153 13 ▶sub type { "invalid_request" }
Subroutine type: called CC=1 SCAR=0.0
154  
155 package OAuth::Lite2::Server::Error::InvalidClient;
156 17 our @ISA = qw(OAuth::Lite2::Server::Error);
157 7 ▶sub code { 401 }
Subroutine code: called CC=1 SCAR=0.0
158 11 ▶sub type { "invalid_client" }
Subroutine type: called CC=1 SCAR=0.0
159  
160 package OAuth::Lite2::Server::Error::UnauthorizedClient;
161 17 our @ISA = qw(OAuth::Lite2::Server::Error);
162 1 ▶sub code { 401 }
Subroutine code: called CC=1 SCAR=0.0
163 1 ▶sub type { "unauthorized_client" }
Subroutine type: called CC=1 SCAR=0.0
164  
165 package OAuth::Lite2::Server::Error::RedirectURIMismatch;
166 17 our @ISA = qw(OAuth::Lite2::Server::Error);
167 3 ▶sub code { 401 }
Subroutine code: called CC=1 SCAR=0.0
168 4 ▶sub type { "redirect_uri_mismatch" }
Subroutine type: called CC=1 SCAR=0.0
169  
170 package OAuth::Lite2::Server::Error::AccessDenied;
171 17 our @ISA = qw(OAuth::Lite2::Server::Error);
172 1 ▶sub code { 401 }
Subroutine code: called CC=1 SCAR=0.0
173 1 ▶sub type { "access_denied" }
Subroutine type: called CC=1 SCAR=0.0
174  
175 package OAuth::Lite2::Server::Error::UnsupportedResponseType;
176 17 our @ISA = qw(OAuth::Lite2::Server::Error);
177 1 ▶sub type { "unsupported_response_type" }
Subroutine type: called CC=1 SCAR=0.0
178  
179 package OAuth::Lite2::Server::Error::UnsupportedResourceType;
180 17 our @ISA = qw(OAuth::Lite2::Server::Error);
181 1 ▶sub type { "unsupported_resource_type" }
Subroutine type: called CC=1 SCAR=0.0
182  
183 package OAuth::Lite2::Server::Error::InvalidGrant;
184 17 our @ISA = qw(OAuth::Lite2::Server::Error);
185 22 ▶sub code { 401 }
Subroutine code: called CC=1 SCAR=0.0
186 33 ▶sub type { "invalid_grant" }
Subroutine type: called CC=1 SCAR=0.0
187  
188 package OAuth::Lite2::Server::Error::UnsupportedGrantType;
189 17 our @ISA = qw(OAuth::Lite2::Server::Error);
190 3 ▶sub type { "unsupported_grant_type" }
Subroutine type: called CC=1 SCAR=0.0
191  
192 package OAuth::Lite2::Server::Error::InvalidScope;
193 17 our @ISA = qw(OAuth::Lite2::Server::Error);
194 1 ▶sub code { 401 }
Subroutine code: called CC=1 SCAR=0.0
195 2 ▶sub type { "invalid_scope" }
Subroutine type: called CC=1 SCAR=0.0
196  
197 package OAuth::Lite2::Server::Error::InvalidToken;
198 17 our @ISA = qw(OAuth::Lite2::Server::Error);
199 19 ▶sub code { 401 }
Subroutine code: called CC=1 SCAR=0.0
200 19 ▶sub type { "invalid_token" }
Subroutine type: called CC=1 SCAR=0.0
201  
202 package OAuth::Lite2::Server::Error::ExpiredTokenLegacy;
203 17 our @ISA = qw(OAuth::Lite2::Server::Error);
204 4 ▶sub code { 401 }
Subroutine code: called CC=1 SCAR=0.0
205 4 ▶sub type { "expired_token" }
Subroutine type: called CC=1 SCAR=0.0
206  
207 package OAuth::Lite2::Server::Error::ExpiredToken;
208 17 our @ISA = qw(OAuth::Lite2::Server::Error);
209 4 ▶sub code { 401 }
Subroutine code: called CC=1 SCAR=0.0
210 4 ▶sub type { "invalid_token" }
Subroutine type: called CC=1 SCAR=0.0
211 7 ▶sub description { "The access token expired" }
Subroutine description: called CC=1 SCAR=0.0
212  
213 package OAuth::Lite2::Server::Error::InsufficientScope;
214 17 our @ISA = qw(OAuth::Lite2::Server::Error);
215 1 ▶sub code { 401 }
Subroutine code: called CC=1 SCAR=0.0
216 1 ▶sub type { "insufficient_scope" }
Subroutine type: called CC=1 SCAR=0.0
217  
218 package OAuth::Lite2::Server::Error::InvalidServerState;
219 17 our @ISA = qw(OAuth::Lite2::Server::Error);
220 3 ▶sub code { 401 }
Subroutine code: called CC=1 SCAR=0.0
221 6 ▶sub type { "invalid_server_state" }
Subroutine type: called CC=1 SCAR=0.0
222  
223 # Generally, the client knows the state of the server by HTTP Status Code.
224 package OAuth::Lite2::Server::Error::TemporarilyUnavailable;
225 17 our @ISA = qw(OAuth::Lite2::Server::Error);
226 1 ▶sub code { 503 }
Subroutine code: called CC=1 SCAR=0.0
227 1 ▶sub type { "temporarily_unavailable" }
Subroutine type: called CC=1 SCAR=0.0
228  
229 package OAuth::Lite2::Server::Error::ServerError;
230 17 our @ISA = qw(OAuth::Lite2::Server::Error);
231 1 ▶sub code { 500 }
Subroutine code: called CC=1 SCAR=0.0
232 1 ▶sub type { "server_error" }
Subroutine type: called CC=1 SCAR=0.0
233  
234 package OAuth::Lite2::Server::Error;
235  
236 =head1 AUTHOR
237  
238 Ryo Ito, E<lt>ritou.06@gmail.comE<gt>
239  
240 Lyo Kato, E<lt>lyo.kato@gmail.comE<gt>
241  
242 =head1 COPYRIGHT AND LICENSE
243  
244 Copyright (C) 2010 by Lyo Kato
245  
246 This library is free software; you can redistribute it and/or modify
247 it under the same terms as Perl itself, either Perl version 5.8.8 or,
248 at your option, any later version of Perl 5 you may have available.
249  
250 =cut
251  
252 17 1;
« blib/lib/OAuth/Lite2/Server/GrantHandler/ServerState.pm ↑ Summary blib/lib/OAuth/Lite2/Formatters.pm »