blib/lib/OxdPackages/GetTokenByCode.pm untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 23 Podpod 0.0% 0 / 19 totaltotal 0.0% 0 / 121 CC 6 SCAR 12.3
CC
6
Cov
0%
setRequestScopes
6.0
setRequestOxdId
6.0
setRequestState
6.0
CRAP 3.4
1 #!/usr/bin/perl
2 # GetTokenByCode.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.2
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.2
39 # @filesource
40 #/
41
42
43 package GetTokenByCode; # This is the "Class"
44 use OxdPackages::OxdClient;
45 use base qw(OxdClient Class::Accessor);
46 use strict;
47 our @ISA = qw(OxdClient); # inherits from OxdClient
48
49 use vars qw($VERSION);
50 $VERSION = '0.01';
51
52 sub new {
53 my $class = shift;
54 my $self = {
55
56 # @var string $request_oxd_id This parameter you must get after registration site in gluu-server
57
58 _request_oxd_id => shift,
59
60 # @var string $request_code This parameter you must get from URL, after redirecting authorization url
61
62 _request_code => shift,
63
64 # @var string $request_state This parameter you must get from URL, after redirecting authorization url
65
66 _request_state => shift,
67
68 # @var string $request_protection_access_token To protect the command with access token
69 _request_protection_access_token => shift,
70
71 # Response parameter from oxd-server
72 # It need to using for get_user_info and logout classes
73 #
74 # @var string $response_access_token
75
76 _response_access_token => shift,
77
78 # Response parameter from oxd-server
79 # Showing user expires time
80 #
81 # @var string $response_expires_in
82
83 _response_expires_in => shift,
84
85 # Response parameter from oxd-server
86 # It need to using for get_user_info and logout classes
87 #
88 # @var string $response_id_token
89
90 _response_id_token => shift,
91
92 # Response parameter from oxd-server
93 # Showing user claimses and data
94 #
95 # @var string $response_id_token_claims
96
97 _response_id_token_claims => shift,
98
99 # Response parameter from oxd-server
100 # Showing user claimses and data
101 #
102 # @var string $response_refresh_token
103
104 _response_refresh_token => shift,
105
106
107 };
108 # Print all the values just for clarification.
109 #print "setRequestOxdId is $self->{_request_oxd_id}<br>";
110 #print "setRequestCode is $self->{_request_code}<br>";
111 #print "setRequestState is $self->{_request_state}<br>";
112 bless $self, $class;
113
114 return $self;
115 }
116
117
118 # @return string
119
120 sub getRequestScopes
121 {
122 my( $self ) = @_;
123 return $self->{_request_scopes};
124 }
125
126
127 # @param string $request_scopes
128 # @return void
129
130 sub setRequestScopes
131 {
132 my ( $self, $request_scopes ) = @_;
133 $self->{_request_scopes} = $request_scopes if defined($request_scopes);
134 return $self->{_request_scopes};
135 }
136
137
138 # @return string
139
140 sub getRequestOxdId
141 {
142 my( $self ) = @_;
143 return $self->{_request_oxd_id};
144 }
145
146
147 # @param string $request_oxd_id
148 # @return void
149
150 sub setRequestOxdId
151 {
152 my ( $self, $request_oxd_id ) = @_;
153 $self->{_request_oxd_id} = $request_oxd_id if defined($request_oxd_id);
154 return $self->{_request_oxd_id};
155 }
156
157
158 # @return string
159
160 sub getRequestState
161 {
162 my( $self ) = @_;
163 return $self->{_request_state};
164 }
165
166
167 # @param string $request_state
168 # @return void
169
170 sub setRequestState
171 {
172 my ( $self, $request_state ) = @_;
173 $self->{_request_state} = $request_state if defined($request_state);
174 return $self->{_request_state};
175 }
176
177
178 # @return string
179
180 sub getRequestCode
181 {
182 my( $self ) = @_;
183 return $self->{_request_code};
184 }
185
186
187 # @param string $request_code
188 # @return void
189
190 sub setRequestCode
191 {
192 my ( $self, $request_code ) = @_;
193 $self->{_request_code} = $request_code if defined($request_code);
194 return $self->{_request_code};
195 }
196
197 # @return array
198 sub getRequestProtectionAccessToken
199 {
200 my( $self ) = @_;
201 return $self->{_request_protection_access_token};
202 }
203
204
205 # @param array $request_protection_access_token
206 # @return void
207 sub setRequestProtectionAccessToken
208 {
209 my ( $self, $request_protection_access_token ) = @_;
210 $self->{_request_protection_access_token} = $request_protection_access_token if defined($request_protection_access_token);
211 return $self->{_request_protection_access_token};
212 }
213
214
215 # @return string
216
217 sub getResponseAccessToken
218 {
219 my( $self ) = @_;
220 $self->{_response_access_token} = $self->getResponseData()->{access_token};
221 return $self->{_response_access_token};
222 }
223
224
225 # @return string
226
227 sub getResponseExpiresIn
228 {
229 my( $self ) = @_;
230 $self->{_response_expires_in} = $self->getResponseData()->{expires_in};
231 return $self->{_response_expires_in};
232 }
233
234
235 # @return string
236
237 sub getResponseIdToken
238 {
239 my( $self ) = @_;
240 $self->{_response_id_token} = $self->getResponseData()->{id_token};
241 return $self->{_response_id_token};
242 }
243
244
245 # @return string
246
247 sub getResponseIdTokenClaims
248 {
249 my( $self ) = @_;
250 $self->{_response_id_token_claims} = $self->getResponseData()->{id_token_claims};
251 return $self->{_response_id_token_claims};
252 }
253
254
255 # @return string
256
257 sub getResponseRefreshToken
258 {
259 my( $self ) = @_;
260 $self->{_response_refresh_token} = $self->getResponseData()->{refresh_token};
261 return $self->{_response_refresh_token};
262 }
263
264
265 # Protocol command to oxd server
266 # @return void
267
268 sub setCommand
269 {
270 my ( $self, $command ) = @_;
271 $self->{_command} = 'get_tokens_by_code';
272 return $self->{_command};
273 }
274
275 # Protocol command to oXD to http server
276 # @return void
277
278 sub sethttpCommand
279 {
280 my ( $self, $httpCommand ) = @_;
281 $self->{_httpcommand} = 'get-tokens-by-code';
282 return $self->{_httpcommand};
283 }
284
285 # Method: setParams
286 # This method sets the parameters for get_tokens_by_code command.
287 # This module uses `request` method of OxdClient module for sending request to oxd-server
288 #
289 # Parameters:
290 #
291 # string $oxd_id - (Required) oxd Id from Client registration
292 #
293 # string $code - (Required) Code from OP redirect URL
294 #
295 # string $state - (Required) State from OP redirect URL
296 #
297 # string $protection_access_token - Protection Acccess Token. OPTIONAL for `oxd-server` but REQUIRED for `oxd-https-extension`
298 #
299 # Returns:
300 # void
301 #
302 # This module uses `getResponseObject` method of OxdClient module for getting response from oxd.
303 #
304 # *Example response from getResponseObject:*
305 # --- Code
306 # { "status": "ok", "data": { "access_token": "cfa5b25f-09d4-47bf-8762-98719406ace2", "expires_in": 299, "refresh_token": "51798a79-5be4-47d1-a898-4a65fe207b5c", "id_token": "eyJraWQiOiIdfgfdvcdyhMltA", "id_token_claims": { "iss": ["https://idp-hostname"], "sub": ["SGUMcFlAj3QlkOQVgwYpSozbjvynk4B2VNpr-mDnuVw"], "aud": ["@!4116.DF7C.62D4.D0CF!0001!D420.A5E5!0008!6156.5BD4.5F9B.D172"], "nonce": ["4pn3vgisdg4em0ups2ud79iig5"], "exp": [1513861298], "iat": [1513857698], "at_hash": ["8tCEomWN_VySJwkJ4lxYfA"] } } }
307 # ---
308 #
309 sub setParams
310 {
311 my ( $self, $params ) = @_;
312 my $paramsArray = {
313 "oxd_id" => $self->getRequestOxdId(),
314 "code" => $self->getRequestCode(),
315 "state" => $self->getRequestState(),
316 "protection_access_token"=> $self->getRequestProtectionAccessToken()
317 };
318 #use Data::Dumper;
319 #print Dumper( $paramsArray );
320 $self->{_params} = $paramsArray;
321 return $self->{_params};
322 }
323
324
325 1; # this 1; is neccessary for our class to work