OxdPackages/GetClientToken.pm untested

filter: Statementstmt 0.0% 0 / 84 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 30 Podpod 0.0% 0 / 25 totaltotal 0.0% 0 / 155 CC 9 SCAR 13.0
CC
9
Cov
0%
setRequestClientSecret
6.0
setRequestClientId
6.0
setRequestOpHost
6.0
CRAP 3.7
1 #!/usr/bin/perl
2 # GetClientToken.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_email 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 GetClientToken; # 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
59 # @var string _request_op_host Gluu server url
60 _request_op_host => shift,
61
62 # @var array _request_scope For getting needed scopes from gluu-server
63 _request_scope => [],
64
65 # @var string _request_client_id OpenID provider client id
66 _request_client_id => shift,
67
68 # @var string _request_client_secret OpenID provider client secret
69 _request_client_secret => shift,
70
71 _request_op_discovery_path => shift,
72
73 _request_authentication_method => shift,
74
75 _request_algorithm => shift,
76
77 _request_key_id=> shift,
78
79
80
81 # Response parameter from oxd-server
82 # It is basic parameter for other protocols
83 #
84 # @var string _response_access_token
85 _response_access_token => shift,
86
87 # @var string _response_expires_in
88 _response_expires_in => shift,
89
90 # @var string _response_refresh_token
91 _response_refresh_token => shift,
92
93 # Response parameter from oxd-server
94 #
95 # @var string _response_scope
96 _response_scope => shift,
97 };
98 #print "<br>";
99 bless $self, $class;
100 return $self;
101 }
102 sub _initialize {}
103
104 # @return string
105 sub getRequestClientSecret{
106 my( $self ) = @_;
107 return $self->{_request_client_secret};
108 }
109
110 # @param string $request_client_secret
111 sub setRequestClientSecret{
112 my ( $self, $request_client_secret ) = @_;
113 $self->{_request_client_secret} = $request_client_secret if defined($request_client_secret);
114 return $self->{_request_client_secret};
115 }
116
117 # @return string
118 sub getRequestClientId{
119 my( $self ) = @_;
120 return $self->{_request_client_id};
121 }
122
123 # @param string $request_client_id
124 sub setRequestClientId{
125 my ( $self, $request_client_id ) = @_;
126 $self->{_request_client_id} = $request_client_id if defined($request_client_id);
127 return $self->{_request_client_id};
128 }
129
130 # @param string $request_op_host
131 # @return void
132 sub setRequestOpHost {
133 my ( $self, $request_op_host ) = @_;
134 $self->{_request_op_host} = $request_op_host if defined($request_op_host);
135 return $self->{_request_op_host};
136 }
137
138 # @return string
139 sub getRequestOpHost {
140 my( $self ) = @_;
141 return $self->{_request_op_host};
142 }
143
144 # @return string
145 sub getRequestOpDiscoveryPath{
146 my( $self ) = @_;
147 return $self->{_request_op_discovery_path};
148 }
149
150 # @param string $request_op_discovery_path
151 # @return void
152 sub setRequestOpDiscoveryPath{
153 my ( $self, $request_op_discovery_path ) = @_;
154 $self->{_request_op_discovery_path} = $request_op_discovery_path if defined($request_op_discovery_path);
155 return $self->{_request_op_discovery_path};
156 }
157
158 # @return string
159 sub getRequestAuthenticationMethod {
160 my( $self ) = @_;
161 return $self->{_request_authentication_method};
162 }
163
164 # @param string $request_authentication_method
165 # @return void
166 sub setRequestAuthenticationMethod {
167 my ( $self, $request_authentication_method ) = @_;
168 $self->{_request_authentication_method} = $request_authentication_method if defined($request_authentication_method);
169 return $self->{_request_authentication_method};
170 }
171
172 # @return string
173 sub getRequestAlgorithm {
174 my( $self ) = @_;
175 return $self->{_request_algorithm};
176 }
177
178 # @param string $request_algorithm
179 # @return void
180 sub setRequestAlgorithm {
181 my ( $self, $request_algorithm ) = @_;
182 $self->{_request_algorithm} = $request_algorithm if defined($request_algorithm);
183 return $self->{_request_algorithm};
184 }
185
186 # @return string
187 sub getRequestKeyId {
188 my( $self ) = @_;
189 return $self->{_request_key_id};
190 }
191
192 # @param string $request_key_id
193 # @return void
194 sub setRequestKeyId {
195 my ( $self, $request_key_id ) = @_;
196 $self->{_request_key_id} = $request_key_id if defined($request_key_id);
197 return $self->{_request_key_id};
198 }
199
200 # @return array
201 sub getRequestScope{
202 my( $self ) = @_;
203 return $self->{_request_scope};
204 }
205
206 # @param array $request_scope
207 # @return void
208 sub setRequestScope{
209 my ( $self, $request_scope ) = @_;
210 $self->{_request_scope} = $request_scope if defined($request_scope);
211 return $self->{_request_scope};
212 }
213
214 # @return string
215 sub getResponseAccessToken {
216 my( $self ) = @_;
217 $self->{_response_access_token} = $self->getResponseData()->{access_token};
218 return $self->{_response_access_token};
219 }
220
221 # @return int
222 sub getResponseExpiresIn {
223 my( $self ) = @_;
224 $self->{_response_expires_in} = $self->getResponseData()->{expires_in};
225 return $self->{_response_expires_in};
226 }
227
228 # @return string
229 sub getResponseRefreshToken {
230 my( $self ) = @_;
231 $self->{_response_refresh_token} = $self->getResponseData()->{refresh_token};
232 return $self->{_response_refresh_token};
233 }
234
235 # @return string
236 sub getResponseScope {
237 my( $self ) = @_;
238 $self->{_response_scope} = $self->getResponseData()->{scope};
239 return $self->{_response_scope};
240 }
241
242 # Protocol command to oxd server
243 # @return void
244 sub setCommand{
245 # my $command = 'get_client_token';
246 my ( $self, $command ) = @_;
247 $self->{_command} = 'get_client_token';
248 return $self->{_command};
249 #return $command;
250 }
251
252 # Protocol command to oxd to http server
253 # @return void
254 sub sethttpCommand{
255 # my $httpCommand = 'get-client-token';
256 my ( $self, $httpCommand ) = @_;
257 $self->{_httpcommand} = 'get-client-token';
258 return $self->{_httpcommand};
259 #return $httpcommand;
260 }
261
262 # Method: setParams
263 # This method sets the parameters for get_client_token command.
264 # This module uses `request` method of OxdClient module for sending request to oxd-server
265 #
266 # Parameters:
267 #
268 # string $client_id - (Required) Client Id from Client registration
269 #
270 # string $client_secret - (Required) Client Secret. Must be used together with ClientId.
271 #
272 # string $op_host - (Required) Url that must points to a valid OpenID Connect Provider that supports client registration like Gluu Server.
273 #
274 # string $op_discovery_path - (Optional) Path to discovery document
275 #
276 # array $scope - (Optional) Scope
277 #
278 # string $authentication_method - (Optional) If value is missed then basic authentication is used. Otherwise it's possible to set `private_key_jwt` value for Private Key authentication.
279 #
280 # string $algorithm - (Optional) Required if authentication_method=private_key_jwt. Valid values are none, HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512
281 #
282 # string $key_id - (Optional) Required if authentication_method=private_key_jwt. It has to be valid key id from key store.
283 #
284 # Returns:
285 # void
286 #
287 # This module uses `getResponseObject` method of OxdClient module for getting response from oxd.
288 #
289 # *Example response from getResponseObject:*
290 # --- Code
291 # { "status": "ok", "data": { "access_token": "7ec389c5-64f8-49a3-a80c-e3e16d134bcb", "expires_in": 299, "refresh_token": null, "scope": "openid" } }
292 # ---
293 #
294 sub setParams{
295
296 my ( $self, $params ) = @_;
297 #use Data::Dumper;
298 my $paramsArray = {
299 "client_id"=> $self->getRequestClientId(),
300 "client_secret"=> $self->getRequestClientSecret(),
301 "op_host" => $self->getRequestOpHost(),
302 "op_discovery_path" => $self->getRequestOpDiscoveryPath(),
303 "scope" => $self->getRequestScope(),
304 "authentication_method" => $self->getRequestAuthenticationMethod(),
305 "algorithm" => $self->getRequestAlgorithm(),
306 "key_id" => $self->getRequestKeyId()
307 };
308
309 $self->{_params} = $paramsArray;
310 return $self->{_params};
311 #print Dumper( $params );
312 #return $paramsArray;
313 }
314
315 1; # this 1; is neccessary for our class to work