blib/lib/OxdPackages/GetClientToken.pm untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 24 Podpod 0.0% 0 / 19 totaltotal 0.0% 0 / 122 CC 6 SCAR 12.2
CC
6
Cov
0%
setRequestClientSecret
6.0
setRequestClientId
6.0
setRequestOpHost
6.0
CRAP 3.4
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.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 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
74
75 # Response parameter from oxd-server
76 # It is basic parameter for other protocols
77 #
78 # @var string _response_access_token
79 _response_access_token => shift,
80
81 # @var string _response_expires_in
82 _response_expires_in => shift,
83
84 # @var string _response_refresh_token
85 _response_refresh_token => shift,
86
87 # Response parameter from oxd-server
88 #
89 # @var string _response_scope
90 _response_scope => shift,
91 };
92 #print "<br>";
93 bless $self, $class;
94 return $self;
95 }
96 sub _initialize {}
97
98 # @return string
99 sub getRequestClientSecret{
100 my( $self ) = @_;
101 return $self->{_request_client_secret};
102 }
103
104 # @param string $request_client_secret
105 sub setRequestClientSecret{
106 my ( $self, $request_client_secret ) = @_;
107 $self->{_request_client_secret} = $request_client_secret if defined($request_client_secret);
108 return $self->{_request_client_secret};
109 }
110
111 # @return string
112 sub getRequestClientId{
113 my( $self ) = @_;
114 return $self->{_request_client_id};
115 }
116
117 # @param string $request_client_id
118 sub setRequestClientId{
119 my ( $self, $request_client_id ) = @_;
120 $self->{_request_client_id} = $request_client_id if defined($request_client_id);
121 return $self->{_request_client_id};
122 }
123
124 # @param string $request_op_host
125 # @return void
126 sub setRequestOpHost {
127 my ( $self, $request_op_host ) = @_;
128 $self->{_request_op_host} = $request_op_host if defined($request_op_host);
129 return $self->{_request_op_host};
130 }
131
132 # @return string
133 sub getRequestOpHost {
134 my( $self ) = @_;
135 return $self->{_request_op_host};
136 }
137
138 # @return array
139 sub getRequestOpDiscoveryPath{
140 my( $self ) = @_;
141 return $self->{_request_op_discovery_path};
142 }
143
144 # @param array $request_op_discovery_path
145 # @return void
146 sub setRequestOpDiscoveryPath{
147 my ( $self, $request_op_discovery_path ) = @_;
148 $self->{_request_op_discovery_path} = $request_op_discovery_path if defined($request_op_discovery_path);
149 return $self->{_request_op_discovery_path};
150 }
151
152 # @return array
153 sub getRequestScope{
154 my( $self ) = @_;
155 return $self->{_request_scope};
156 }
157
158 # @param array $request_scope
159 # @return void
160 sub setRequestScope{
161 my ( $self, $request_scope ) = @_;
162 $self->{_request_scope} = $request_scope if defined($request_scope);
163 return $self->{_request_scope};
164 }
165
166 # @return string
167 sub getResponseAccessToken {
168 my( $self ) = @_;
169 $self->{_response_access_token} = $self->getResponseData()->{access_token};
170 return $self->{_response_access_token};
171 }
172
173 # @return int
174 sub getResponseExpiresIn {
175 my( $self ) = @_;
176 $self->{_response_expires_in} = $self->getResponseData()->{expires_in};
177 return $self->{_response_expires_in};
178 }
179
180 # @return string
181 sub getResponseRefreshToken {
182 my( $self ) = @_;
183 $self->{_response_refresh_token} = $self->getResponseData()->{refresh_token};
184 return $self->{_response_refresh_token};
185 }
186
187 # @return string
188 sub getResponseScope {
189 my( $self ) = @_;
190 $self->{_response_scope} = $self->getResponseData()->{scope};
191 return $self->{_response_scope};
192 }
193
194 # Protocol command to oxd server
195 # @return void
196 sub setCommand{
197 # my $command = 'get_client_token';
198 my ( $self, $command ) = @_;
199 $self->{_command} = 'get_client_token';
200 return $self->{_command};
201 #return $command;
202 }
203
204 # Protocol command to oxd to http server
205 # @return void
206 sub sethttpCommand{
207 # my $httpCommand = 'get-client-token';
208 my ( $self, $httpCommand ) = @_;
209 $self->{_httpcommand} = 'get-client-token';
210 return $self->{_httpcommand};
211 #return $httpcommand;
212 }
213
214 # Method: setParams
215 # This method sets the parameters for get_client_token command.
216 # This module uses `request` method of OxdClient module for sending request to oxd-server
217 #
218 # Parameters:
219 #
220 # string $client_id - (Required) Client Id from Client registration
221 #
222 # string $client_secret - (Required) Client Secret. Must be used together with ClientId.
223 #
224 # string $op_host - (Required) Url that must points to a valid OpenID Connect Provider that supports client registration like Gluu Server.
225 #
226 # string $op_discovery_path - (Optional) Path to discovery document
227 #
228 # array $scope - (Optional) Scope
229 #
230 # Returns:
231 # void
232 #
233 # This module uses `getResponseObject` method of OxdClient module for getting response from oxd.
234 #
235 # *Example response from getResponseObject:*
236 # --- Code
237 # { "status": "ok", "data": { "access_token": "7ec389c5-64f8-49a3-a80c-e3e16d134bcb", "expires_in": 299, "refresh_token": null, "scope": "openid" } }
238 # ---
239 #
240 sub setParams{
241
242 my ( $self, $params ) = @_;
243 #use Data::Dumper;
244 my $paramsArray = {
245 "client_id"=> $self->getRequestClientId(),
246 "client_secret"=> $self->getRequestClientSecret(),
247 "op_host" => $self->getRequestOpHost(),
248 "op_discovery_path" => $self->getRequestOpDiscoveryPath(),
249 "scope" => $self->getRequestScope()
250 };
251
252 $self->{_params} = $paramsArray;
253 return $self->{_params};
254 #print Dumper( $params );
255 #return $paramsArray;
256 }
257
258 1; # this 1; is neccessary for our class to work