blib/lib/OxdPackages/OxdSetupClient.pm untested

filter: Statementstmt 0.0% 0 / 157 Branchbran 0.0% 0 / 42 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 58 Podpod 0.0% 0 / 53 totaltotal 0.0% 0 / 310 CC 22 SCAR 14.6
CC
22
Cov
0%
setRequestApplicationType
12.0
setRequestClientName
6.0
setRequestClientSecret
6.0
CRAP 4.3
1 #!/usr/bin/perl
2 # OxdSetupClient.pm, a number as an object
3
4 #
5 # Gluu-oxd-library
6 #
7 # An open source application library for Perl
8 #
9 # This content is released under the MIT License (MIT)
10 #
11 # Copyright (c) 2018, Gluu inc, USA, Austin
12 #
13 # Permission is hereby granted, free of charge, to any person obtaining a copy
14 # of this software and associated documentation files (the "Software"), to deal
15 # in the Software without restriction, including without limitation the rights
16 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 # copies of the Software, and to permit persons to whom the Software is
18 # furnished to do so, subject to the following conditions:
19 #
20 # The above copyright notice and this permission notice shall be included in
21 # all copies or substantial portions of the Software.
22 #
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 # THE SOFTWARE.
30 #
31 # @package Gluu-oxd-library
32 # @version 3.1.3
33 # @author Sobhan Panda
34 # @author sobhan@centroxy.com
35 # @copyright Copyright (c) 2018, Gluu inc federation (https://gluu.org/)
36 # @license http://opensource.org/licenses/MIT MIT License
37 # @link https://gluu.org/
38 # @since Version 3.1.3
39 # @filesource
40 #/
41
42 use JSON::PP;
43
44 package OxdSetupClient; # This is the "Class"
45 use vars qw($VERSION);
46 $VERSION = '0.01';
47
48 use OxdPackages::OxdClient;
49 use base qw(OxdClient Class::Accessor);
50 #use base 'OxdClient';
51 use strict;
52 our @ISA = qw(OxdClient); # inherits from OxdClient
53
54 sub new {
55 my $class = shift;
56
57 my $self = {
58 #_firstName => shift,
59 #_lastName => shift,
60 #_ssn => shift,
61
62 # @var string _request_op_host Gluu server url
63 _request_op_host => shift,
64
65 # @var array _request_acr_values Gluu login acr type, can be basic, duo, u2f, gplus and etc.
66 _request_acr_values => [],
67
68 # @var string _request_authorization_redirect_uri Site authorization redirect uri
69 _request_authorization_redirect_uri => shift,
70
71 # @var string _request_post_logout_redirect_uri Site logout redirect uri
72 _request_post_logout_redirect_uri => shift,
73
74 # @var array _request_contacts
75 _request_contacts => shift,
76
77 # @var array _request_grant_types OpenID Token Request type
78 _request_grant_types => [],
79
80 #@var array _request_response_types OpenID Authentication response types
81 _request_response_types => [],
82
83 # @var array _request_scope For getting needed scopes from gluu-server
84 _request_scope => [],
85
86 # @var string _request_application_type web or mobile
87 _request_application_type => shift,
88
89 # @var string _request_client_id OpenID provider client id
90 _request_client_id => shift,
91
92 # @var string _request_client_name OpenID provider client name
93 _request_client_name => shift,
94
95 # @var string _request_client_secret OpenID provider client secret
96 _request_client_secret => shift,
97
98
99 # @var string _request_client_jwks_uri
100 _request_client_jwks_uri => shift,
101
102 # @var string _request_client_token_endpoint_auth_method
103 _request_client_token_endpoint_auth_method => shift,
104
105 # @var array _request_client_sector_identifier_uri
106 _request_client_sector_identifier_uri => shift,
107
108 # @var array _request_client_request_uris
109 _request_client_request_uris => shift,
110
111 # @var array _request_client_logout_uris
112 _request_client_frontchannel_logout_uris => shift,
113
114 # @var array _request_ui_locales
115 _request_ui_locales => shift,
116
117 # @var array _request_claims_locales
118 _request_claims_locales => shift,
119
120 # @var string _request_claims_redirect_uri
121 _request_claims_redirect_uri => shift,
122
123
124 # Response parameter from oxd-server
125 # It is basic parameter for other protocols
126 #
127 # @var string _response_oxd_id
128 _response_oxd_id => shift,
129
130 # @var string _response_op_host
131 _response_op_host => shift,
132
133 # @var string _response_client_id
134 _response_client_id => shift,
135
136 # @var string _response_client_secret
137 _response_client_secret => shift,
138
139 # @var string _response_client_registration_access_token
140 _response_client_registration_access_token => shift,
141
142 # @var string _response_client_registration_client_uri
143 _response_client_registration_client_uri => shift,
144
145 # @var string _response_client_id_issued_at
146 _response_client_id_issued_at => shift,
147
148 # @var string _response_client_secret_expires_at
149 _response_client_secret_expires_at => shift,
150
151 };
152 # Print all the values just for clarification.
153 #print "First Name is $self->{_firstName}\n";
154 #print "Last Name is $self->{_lastName}\n";
155 #print "URl is $self->{_request_authorization_redirect_uri}\n";
156 #print "<br>";
157 bless $self, $class;
158 return $self;
159 }
160 sub _initialize {}
161 # @return string
162 sub getRequestClientName{
163 my( $self ) = @_;
164 return $self->{_request_client_name};
165 }
166
167 # @param string $request_client_name
168 sub setRequestClientName{
169 my ( $self, $request_client_name ) = @_;
170 $self->{_request_client_name} = $request_client_name if defined($request_client_name);
171 return $self->{_request_client_name};
172 }
173
174 # @return string
175 sub getRequestClientSecret{
176 my( $self ) = @_;
177 return $self->{_request_client_secret};
178 }
179
180 # @param string $request_client_secret
181 sub setRequestClientSecret{
182 my ( $self, $request_client_secret ) = @_;
183 $self->{_request_client_secret} = $request_client_secret if defined($request_client_secret);
184 return $self->{_request_client_secret};
185 }
186
187 # @return string
188 sub getRequestClientId{
189 my( $self ) = @_;
190 return $self->{_request_client_id};
191 }
192
193 # @param string $request_client_id
194 sub setRequestClientId{
195 my ( $self, $request_client_id ) = @_;
196 $self->{_request_client_id} = $request_client_id if defined($request_client_id);
197 return $self->{_request_client_id};
198 }
199
200 # @param string $request_op_host
201 # @return void
202 sub setRequestOpHost {
203 my ( $self, $request_op_host ) = @_;
204 $self->{_request_op_host} = $request_op_host if defined($request_op_host);
205 return $self->{_request_op_host};
206 }
207
208 # @return string
209 sub getRequestOpHost {
210 my( $self ) = @_;
211 return $self->{_request_op_host};
212 }
213
214 # @return array
215 sub getRequestClientLogoutUris{
216 my( $self ) = @_;
217 return $self->{_request_client_frontchannel_logout_uris};
218 }
219
220 # @param array $request_client_logout_uris
221 # @return void
222 sub setRequestClientLogoutUris{
223 my ( $self, $request_client_frontchannel_logout_uris ) = @_;
224 $self->{_request_client_frontchannel_logout_uris} = $request_client_frontchannel_logout_uris if defined($request_client_frontchannel_logout_uris);
225 return $self->{_request_client_frontchannel_logout_uris};
226 }
227
228 # @return array
229 sub getRequestResponseTypes{
230 my( $self ) = @_;
231 return $self->{_request_response_types};
232 }
233
234 # @param array $request_response_types
235 # @return void
236 sub setRequestResponseTypes{
237 my ( $self, $request_response_types ) = @_;
238 $self->{_request_response_types} = $request_response_types if defined($request_response_types);
239 return $self->{_request_response_types};
240 }
241
242 # @return array
243 sub getRequestGrantTypes{
244 my( $self ) = @_;
245 return $self->{_request_grant_types};
246 }
247
248 # @param array $request_grant_types
249 # @return void
250 sub setRequestGrantTypes{
251 my ( $self, $request_grant_types ) = @_;
252 $self->{_request_grant_types} = $request_grant_types if defined($request_grant_types);
253 return $self->{_request_grant_types};
254 }
255
256 # @return array
257 sub getRequestScope{
258 my( $self ) = @_;
259 return $self->{_request_scope};
260 }
261
262 # @param array $request_scope
263 # @return void
264 sub setRequestScope{
265 my ( $self, $request_scope ) = @_;
266 $self->{_request_scope} = $request_scope if defined($request_scope);
267 return $self->{_request_scope};
268 }
269
270 # @return string
271 sub getRequestPostLogoutRedirectUri{
272 my( $self ) = @_;
273 return $self->{_request_post_logout_redirect_uri};
274 }
275
276 # @param string $request_post_logout_redirect_uri
277 # @return void
278 sub setRequestPostLogoutRedirectUri{
279 my ( $self, $request_post_logout_redirect_uri ) = @_;
280 $self->{_request_post_logout_redirect_uri} = $request_post_logout_redirect_uri if defined($request_post_logout_redirect_uri);
281 return $self->{_request_post_logout_redirect_uri};
282 }
283
284 # @return string
285 sub getRequestClientJwksUri{
286 my( $self ) = @_;
287 return $self->{_request_client_jwks_uri};
288 }
289
290 # @param string $request_client_jwks_uri
291 # @return void
292 sub setRequestClientJwksUri{
293 my ( $self, $request_client_jwks_uri ) = @_;
294 $self->{_request_client_jwks_uri} = $request_client_jwks_uri if defined($request_client_jwks_uri);
295 return $self->{_request_client_jwks_uri};
296 }
297
298 # @return array
299 sub getRequestClientSectorIdentifierUri{
300 my( $self ) = @_;
301 return $self->{_request_client_sector_identifier_uri};
302 }
303
304 # @param array $request_client_sector_identifier_uri
305 sub setRequestClientSectorIdentifierUri{
306 my ( $self, $request_client_sector_identifier_uri ) = @_;
307 $self->{_request_client_sector_identifier_uri} = $request_client_sector_identifier_uri if defined($request_client_sector_identifier_uri);
308 return $self->{_request_client_sector_identifier_uri};
309 }
310
311 # @return string
312 sub getRequestClientTokenEndpointAuthMethod{
313 my( $self ) = @_;
314 return $self->{_request_client_token_endpoint_auth_method};
315 }
316
317 # @param string $request_client_token_endpoint_auth_method
318 # @return void
319 sub setRequestClientTokenEndpointAuthMethod{
320 my ( $self, $request_client_token_endpoint_auth_method ) = @_;
321 $self->{_request_client_token_endpoint_auth_method} = $request_client_token_endpoint_auth_method if defined($request_client_token_endpoint_auth_method);
322 return $self->{_request_client_token_endpoint_auth_method};
323 }
324
325 # @return array
326 sub getRequestClientRequestUris{
327 my( $self ) = @_;
328 return $self->{_request_client_request_uris};
329 }
330
331 # @param array $request_client_request_uris
332 # @return void
333 sub setRequestClientRequestUris{
334 my ( $self, $request_client_request_uris ) = @_;
335 $self->{_request_client_request_uris} = $request_client_request_uris if defined($request_client_request_uris);
336 return $self->{_request_client_request_uris};
337 }
338
339 # @return string
340 sub getRequestApplicationType{
341 my( $self ) = @_;
342 return $self->{_request_application_type};
343 }
344
345 # @param string $request_application_type
346 # @return void
347 sub setRequestApplicationType{
348 my ( $self, $request_application_type ) = @_;
349
350 $request_application_type = $request_application_type ? $request_application_type : 'web';
351
352 $self->{_request_application_type} = $request_application_type if defined($request_application_type);
353 return $self->{_request_application_type};
354 }
355
356 # @return string
357 sub getRequestAuthorizationRedirectUri{
358 my( $self ) = @_;
359 return $self->{_request_authorization_redirect_uri};
360 }
361
362 # @param string $request_authorization_redirect_uri
363 # @return void
364 sub setRequestAuthorizationRedirectUri{
365 my ( $self, $request_authorization_redirect_uri ) = @_;
366 $self->{_request_authorization_redirect_uri} = $request_authorization_redirect_uri if defined($request_authorization_redirect_uri);
367 return $self->{_request_authorization_redirect_uri};
368 }
369
370 # @return array
371 sub getRequestAcrValues{
372 my( $self ) = @_;
373 return $self->{_request_acr_values};
374 }
375
376 # @param array $request_acr_values
377 # @return void
378 sub setRequestAcrValues{
379 my ( $self, $request_acr_values ) = @_;
380 $self->{_request_acr_values} = $request_acr_values if defined($request_acr_values);
381 return $self->{_request_acr_values};
382 }
383
384 # @return array
385 sub getRequestContacts{
386 my( $self ) = @_;
387 return $self->{_request_contacts};
388 }
389
390 # @param array $request_contacts
391 # @return void
392 sub setRequestContacts{
393 my ( $self, $request_contacts ) = @_;
394 $self->{_request_contacts} = $request_contacts if defined($request_contacts);
395 return $self->{_request_contacts};
396 }
397
398 # @return string
399 sub getResponseOxdId {
400 my( $self ) = @_;
401 $self->{_response_oxd_id} = $self->getResponseData()->{oxd_id};
402 return $self->{_response_oxd_id};
403 }
404
405 # @return string
406 sub getResponseOpHost {
407 my( $self ) = @_;
408 $self->{_response_op_host} = $self->getResponseData()->{op_host};
409 return $self->{_response_op_host};
410 }
411
412 # @return string
413 sub getResponseClientId {
414 my( $self ) = @_;
415 $self->{_response_client_id} = $self->getResponseData()->{client_id};
416 return $self->{_response_client_id};
417 }
418
419 # @return string
420 sub getResponseClientSecret {
421 my( $self ) = @_;
422 $self->{_response_client_secret} = $self->getResponseData()->{client_secret};
423 return $self->{_response_client_secret};
424 }
425
426 # @return string
427 sub getResponseClientRegistrationAccessToken {
428 my( $self ) = @_;
429 $self->{_response_client_registration_access_token} = $self->getResponseData()->{client_registration_access_token};
430 return $self->{_response_client_registration_access_token};
431 }
432
433 # @return string
434 sub getResponseClientRegistrationClientUri {
435 my( $self ) = @_;
436 $self->{_response_client_registration_client_uri} = $self->getResponseData()->{client_registration_client_uri};
437 return $self->{_response_client_registration_client_uri};
438 }
439
440 # @return string
441 sub getResponseClientIdIssuedAt {
442 my( $self ) = @_;
443 $self->{_response_client_id_issued_at} = $self->getResponseData()->{client_id_issued_at};
444 return $self->{_response_client_id_issued_at};
445 }
446
447 # @return string
448 sub getResponseClientSecretExpiresAt {
449 my( $self ) = @_;
450 $self->{_response_client_secret_expires_at} = $self->getResponseData()->{client_secret_expires_at};
451 return $self->{_response_client_secret_expires_at};
452 }
453
454 # @return array
455 sub getRequestUiLocales{
456 my( $self ) = @_;
457 return $self->{_request_ui_locales};
458 }
459
460 # @param array $request_ui_locales
461 sub setRequestUiLocales{
462 my ( $self, $request_ui_locales ) = @_;
463 $self->{_request_ui_locales} = $request_ui_locales if defined($request_ui_locales);
464 return $self->{_request_ui_locales};
465 }
466
467 # @return array
468 sub getRequestClaimsLocales{
469 my( $self ) = @_;
470 return $self->{_request_claims_locales};
471 }
472
473 # @param array $request_claims_locales
474 sub setRequestClaimsLocales{
475 my ( $self, $request_claims_locales ) = @_;
476 $self->{_request_claims_locales} = $request_claims_locales if defined($request_claims_locales);
477 return $self->{_request_claims_locales};
478 }
479
480
481 # @return string
482 sub getRequestClaimsRedirectUri {
483 my( $self ) = @_;
484 return $self->{_request_claims_redirect_uri};
485 }
486
487 # @param string $request_client_secret
488 sub setRequestClaimsRedirectUri {
489 my ( $self, $request_client_redirect_uri ) = @_;
490 $self->{_request_claims_redirect_uri} = $request_client_redirect_uri if defined($request_client_redirect_uri);
491 return $self->{_request_claims_redirect_uri};
492 }
493
494 # Protocol command to oxd server
495 # @return void
496 sub setCommand{
497 # my $command = 'setup_client';
498 my ( $self, $command ) = @_;
499 $self->{_command} = 'setup_client';
500 return $self->{_command};
501 #return $command;
502 }
503
504 # Protocol command to oxd to http server
505 # @return void
506 sub sethttpCommand{
507 # my $httpCommand = 'setup-client';
508 my ( $self, $httpCommand ) = @_;
509 $self->{_httpcommand} = 'setup-client';
510 return $self->{_httpcommand};
511 #return $httpcommand;
512 }
513
514 # Method: setParams
515 # This method sets the parameters for setup_client command.
516 # This module uses `request` method of OxdClient module for sending request to oxd-server
517 #
518 # Parameters:
519 #
520 # string $authorization_redirect_uri - (Required) Uri to Redirect for Authorization
521 #
522 # string $op_host - (Optional) Url that must points to a valid OpenID Connect Provider that supports client registration like Gluu Server.
523 #
524 # string $post_logout_redirect_uri - (Optional) Uri to Redirect after Logout
525 #
526 # string $application_type - (Optional) Application Type
527 #
528 # array $response_types - (Optional) Response Types
529 #
530 # array $grant_types - (Optional) Grant Types
531 #
532 # array $scope - (Optional) Scope
533 #
534 # array $acr_values - (Optional) ACR Values
535 #
536 # string $client_name - (Optional) Client Name
537 #
538 # string $client_jwks_uri - (Optional) Client JWKS Uri
539 #
540 # string $client_token_endpoint_auth_method - (Optional) Client Token Endpoint Auth Method
541 #
542 # array $client_request_uris - (Optional) Client Request URIs
543 #
544 # array $client_frontchannel_logout_uris - (Optional) Client Front Channel Logout URIs
545 #
546 # array $client_sector_identifier_uri - (Optional) Client Sector Identifier URIs
547 #
548 # array $contacts - (Optional) Contacts
549 #
550 # array $ui_locales - (Optional) UI Locales
551 #
552 # array $claims_locales - (Optional) Claims Locales
553 #
554 # string $client_id - (Optional) Client ID. If value presents, Ignores all other parameters and Skips new client registration forcing to use existing client. ClientSecret is REQUIRED if this parameter is set
555 #
556 # string $client_secret - (Optional) Client Secret. Must be used together with ClientId.
557 #
558 # array $claims_redirect_uri - (Optional) Claims Redirect URI.
559 #
560 # Returns:
561 # void
562 #
563 # This module uses `getResponseObject` method of OxdClient module for getting response from oxd.
564 #
565 # *Example response from getResponseObject:*
566 # --- Code
567 # { "status": "ok", "data": { "oxd_id": "c73134c8-c4ca-4bab-9baa-2e0ca20cc433", "op_host": "https://idp-hostname", "client_id": "@!4116.DF7C.62D4.D0CF!0001!D420.A5E5!0008!616C.398A.1380.1F45", "client_secret": "f996649f-b027-4537-abe5-71b7cb71ebae", "client_registration_access_token": "67e957b8-823e-412d-8e89-616c45b2db62", "client_registration_client_uri": "https://idp-hostname/oxauth/restv1/register?client_id=@!4116.DF7C.62D4.D0CF!0001!D420.A5E5!0008!616C.398A.1380.1F45", "client_id_issued_at": 1513857463, "client_secret_expires_at": 1513943863 } }
568 # ---
569 #
570 sub setParams{
571
572 my ( $self, $params ) = @_;
573 #use Data::Dumper;
574 my $paramsArray = {
575 "authorization_redirect_uri" => $self->getRequestAuthorizationRedirectUri(),
576 "op_host" => $self->getRequestOpHost(),
577 "post_logout_redirect_uri" => $self->getRequestPostLogoutRedirectUri(),
578 "application_type" => $self->getRequestApplicationType(),
579 "response_types"=> $self->getRequestResponseTypes(),
580 "grant_types" => $self->getRequestGrantTypes(),
581 "scope" => $self->getRequestScope(),
582 "acr_values" => $self->getRequestAcrValues(),
583 "client_name"=> $self->getRequestClientName(),
584 "client_jwks_uri" => $self->getRequestClientJwksUri(),
585 "client_token_endpoint_auth_method" => $self->getRequestClientTokenEndpointAuthMethod(),
586 "client_request_uris" => $self->getRequestClientRequestUris(),
587 "client_frontchannel_logout_uris"=> $self->getRequestClientLogoutUris(),
588 "client_sector_identifier_uri"=> $self->getRequestClientSectorIdentifierUri(),
589 "contacts" => $self->getRequestContacts(),
590 "ui_locales" => $self->getRequestUiLocales(),
591 "claims_locales" => $self->getRequestClaimsLocales(),
592 "client_id"=> $self->getRequestClientId(),
593 "client_secret"=> $self->getRequestClientSecret(),
594 "claims_redirect_uri"=> $self->getRequestClaimsRedirectUri(),
595 "oxd_rp_programming_language" => 'perl'
596 };
597
598 $self->{_params} = $paramsArray;
599 return $self->{_params};
600 #print Dumper( $params );
601 #return $paramsArray;
602 }
603
604 1; # this 1; is neccessary for our class to work