| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | ## | ||
| 4 | # Gluu-oxd-library | ||
| 5 | # | ||
| 6 | # An open source application library for Perl | ||
| 7 | # | ||
| 8 | # This content is released under the MIT License (MIT) | ||
| 9 | # | ||
| 10 | # Copyright (c) 2018, Gluu inc, USA, Austin | ||
| 11 | # | ||
| 12 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 13 | # of this software and associated documentation files (the "Software"), to deal | ||
| 14 | # in the Software without restriction, including without limitation the rights | ||
| 15 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 16 | # copies of the Software, and to permit persons to whom the Software is | ||
| 17 | # furnished to do so, subject to the following conditions: | ||
| 18 | # | ||
| 19 | # The above copyright notice and this permission notice shall be included in | ||
| 20 | # all copies or substantial portions of the Software. | ||
| 21 | # | ||
| 22 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 23 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 24 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 25 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 26 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 27 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 28 | # THE SOFTWARE. | ||
| 29 | # | ||
| 30 | # @package Gluu-oxd-library | ||
| 31 | # @version 3.1.3 | ||
| 32 | # @author Inderpal Singh, Sobhan Panda | ||
| 33 | # @author_email inderpal@ourdesignz.com, sobhan@centroxy.com | ||
| 34 | # @copyright Copyright (c) 2018, Gluu inc federation (https://gluu.org/) | ||
| 35 | # @license http://opensource.org/licenses/MIT MIT License | ||
| 36 | # @link https://gluu.org/ | ||
| 37 | # @since Version 3.1.3 | ||
| 38 | # @filesource | ||
| 39 | # | ||
| 40 | |||
| 41 | ## | ||
| 42 | # UMA RP - Get Rpt class | ||
| 43 | # | ||
| 44 | # Class is connecting to oxd-server via socket, and getting GAT from gluu-server. | ||
| 45 | # | ||
| 46 | # @package Gluu-oxd-library | ||
| 47 | # @subpackage Libraries | ||
| 48 | # @category Relying Party (RP) and User Managed Access (UMA) | ||
| 49 | # @author Inderpal Singh, Sobhan Panda | ||
| 50 | # @author inderpal@ourdesignz.com, sobhan@centroxy.com | ||
| 51 | # @see OxdClientSocket | ||
| 52 | # @see OxdClient | ||
| 53 | # @see OxdConfig | ||
| 54 | #/ | ||
| 55 | |||
| 56 | package UmaRpGetRpt; | ||
| 57 | use vars qw($VERSION); | ||
| 58 | $VERSION = '0.01'; | ||
| 59 | use OxdPackages::OxdClient; | ||
| 60 | use base qw(OxdClient Class::Accessor); | ||
| 61 | use strict; | ||
| 62 | our @ISA = qw(OxdClient); # inherits from OxdClient | ||
| 63 | use Data::Dumper; | ||
| 64 | |||
| 65 | sub new { | ||
| 66 | my $class = shift; | ||
| 67 | my $self = { | ||
| 68 | |||
| 69 | # @var string $request_oxd_id This parameter you must get after registration site in gluu-server | ||
| 70 | _request_oxd_id => shift, | ||
| 71 | |||
| 72 | # @var bool $request_force_new Indicates whether return new RPT, in general should be false, so oxd server can cache/reuse same RPT | ||
| 73 | _request_force_new => shift, | ||
| 74 | |||
| 75 | _request_ticket => shift, | ||
| 76 | |||
| 77 | _request_claim_token => shift, | ||
| 78 | |||
| 79 | _request_claim_token_format => shift, | ||
| 80 | |||
| 81 | _request_pct => shift, | ||
| 82 | |||
| 83 | _request_rpt => shift, | ||
| 84 | |||
| 85 | _request_scope => shift, | ||
| 86 | |||
| 87 | _request_state => shift, | ||
| 88 | |||
| 89 | _request_protection_access_token => shift, | ||
| 90 | |||
| 91 | |||
| 92 | # Response parameter from oxd-server | ||
| 93 | # Gluu RP Token | ||
| 94 | # @var string $response_rpt | ||
| 95 | |||
| 96 | _response_rpt => shift, | ||
| 97 | |||
| 98 | _response_status => shift, | ||
| 99 | |||
| 100 | _response_error => shift, | ||
| 101 | |||
| 102 | _response_ticket => shift | ||
| 103 | }; | ||
| 104 | # Print all the values just for clarification. | ||
| 105 | # print "First Name is $self->{_request_oxd_id}\n"; | ||
| 106 | |||
| 107 | # print "<br>"; | ||
| 108 | bless $self, $class; | ||
| 109 | return $self; | ||
| 110 | } | ||
| 111 | |||
| 112 | # @return string | ||
| 113 | sub getRequestOxdId | ||
| 114 | { | ||
| 115 | my( $self ) = @_; | ||
| 116 | return $self->{_request_oxd_id} | ||
| 117 | } | ||
| 118 | |||
| 119 | ## | ||
| 120 | # @param string $request_oxd_id | ||
| 121 | # @return void | ||
| 122 | # | ||
| 123 | sub setRequestOxdId | ||
| 124 | { | ||
| 125 | my ( $self, $request_oxd_id ) = @_; | ||
| 126 | $self->{_request_oxd_id} = $request_oxd_id if defined($request_oxd_id); | ||
| 127 | return $self->{_request_oxd_id}; | ||
| 128 | } | ||
| 129 | |||
| 130 | ## | ||
| 131 | # @return bool | ||
| 132 | # | ||
| 133 | sub getRequestForceNew | ||
| 134 | { | ||
| 135 | my( $self ) = @_; | ||
| 136 | return $self->{_request_force_new}; | ||
| 137 | } | ||
| 138 | |||
| 139 | ## | ||
| 140 | # @param bool $request_force_new | ||
| 141 | # @return void | ||
| 142 | # | ||
| 143 | sub setRequestForceNew | ||
| 144 | { | ||
| 145 | my ( $self, $request_force_new ) = @_; | ||
| 146 | $self->{_request_force_new} = $request_force_new if defined($request_force_new); | ||
| 147 | return $self->{_request_force_new}; | ||
| 148 | } | ||
| 149 | |||
| 150 | |||
| 151 | # @return string | ||
| 152 | sub getRequestTicket | ||
| 153 | { | ||
| 154 | my( $self ) = @_; | ||
| 155 | return $self->{_request_ticket} | ||
| 156 | } | ||
| 157 | |||
| 158 | ## | ||
| 159 | # @param string $request_ticket | ||
| 160 | # @return void | ||
| 161 | # | ||
| 162 | sub setRequestTicket | ||
| 163 | { | ||
| 164 | my ( $self, $request_ticket ) = @_; | ||
| 165 | $self->{_request_ticket} = $request_ticket if defined($request_ticket); | ||
| 166 | return $self->{_request_ticket}; | ||
| 167 | } | ||
| 168 | |||
| 169 | |||
| 170 | # @return string | ||
| 171 | sub getRequestClaimToken | ||
| 172 | { | ||
| 173 | my( $self ) = @_; | ||
| 174 | return $self->{_request_claim_token} | ||
| 175 | } | ||
| 176 | |||
| 177 | ## | ||
| 178 | # @param string $request_claim_token | ||
| 179 | # @return void | ||
| 180 | # | ||
| 181 | sub setRequestClaimToken | ||
| 182 | { | ||
| 183 | my ( $self, $request_claim_token ) = @_; | ||
| 184 | $self->{_request_claim_token} = $request_claim_token if defined($request_claim_token); | ||
| 185 | return $self->{_request_claim_token}; | ||
| 186 | } | ||
| 187 | |||
| 188 | |||
| 189 | # @return string | ||
| 190 | sub getRequestClaimTokenFormat | ||
| 191 | { | ||
| 192 | my( $self ) = @_; | ||
| 193 | return $self->{_request_claim_token_format} | ||
| 194 | } | ||
| 195 | |||
| 196 | ## | ||
| 197 | # @param string $request_claim_token_format | ||
| 198 | # @return void | ||
| 199 | # | ||
| 200 | sub setRequestClaimTokenFormat | ||
| 201 | { | ||
| 202 | my ( $self, $request_claim_token_format ) = @_; | ||
| 203 | $self->{_request_claim_token_format} = $request_claim_token_format if defined($request_claim_token_format); | ||
| 204 | return $self->{_request_claim_token_format}; | ||
| 205 | } | ||
| 206 | |||
| 207 | |||
| 208 | # @return string | ||
| 209 | sub getRequestPCT | ||
| 210 | { | ||
| 211 | my( $self ) = @_; | ||
| 212 | return $self->{_request_pct} | ||
| 213 | } | ||
| 214 | |||
| 215 | ## | ||
| 216 | # @param string $request_pct | ||
| 217 | # @return void | ||
| 218 | # | ||
| 219 | sub setRequestPCT | ||
| 220 | { | ||
| 221 | my ( $self, $request_pct ) = @_; | ||
| 222 | $self->{_request_pct} = $request_pct if defined($request_pct); | ||
| 223 | return $self->{_request_pct}; | ||
| 224 | } | ||
| 225 | |||
| 226 | |||
| 227 | # @return string | ||
| 228 | sub getRequestRPT | ||
| 229 | { | ||
| 230 | my( $self ) = @_; | ||
| 231 | return $self->{_request_rpt} | ||
| 232 | } | ||
| 233 | |||
| 234 | ## | ||
| 235 | # @param string $request_rpt | ||
| 236 | # @return void | ||
| 237 | # | ||
| 238 | sub setRequestRPT | ||
| 239 | { | ||
| 240 | my ( $self, $request_rpt ) = @_; | ||
| 241 | $self->{_request_rpt} = $request_rpt if defined($request_rpt); | ||
| 242 | return $self->{_request_rpt}; | ||
| 243 | } | ||
| 244 | |||
| 245 | |||
| 246 | # @return string | ||
| 247 | sub getRequestScope | ||
| 248 | { | ||
| 249 | my( $self ) = @_; | ||
| 250 | return $self->{_request_scope} | ||
| 251 | } | ||
| 252 | |||
| 253 | ## | ||
| 254 | # @param string $request_scope | ||
| 255 | # @return void | ||
| 256 | # | ||
| 257 | sub setRequestScope | ||
| 258 | { | ||
| 259 | my ( $self, $request_scope ) = @_; | ||
| 260 | $self->{_request_scope} = $request_scope if defined($request_scope); | ||
| 261 | return $self->{_request_scope}; | ||
| 262 | } | ||
| 263 | |||
| 264 | |||
| 265 | # @return string | ||
| 266 | sub getRequestState | ||
| 267 | { | ||
| 268 | my( $self ) = @_; | ||
| 269 | return $self->{_request_state} | ||
| 270 | } | ||
| 271 | |||
| 272 | ## | ||
| 273 | # @param string $request_state | ||
| 274 | # @return void | ||
| 275 | # | ||
| 276 | sub setRequestState | ||
| 277 | { | ||
| 278 | my ( $self, $request_state ) = @_; | ||
| 279 | $self->{_request_state} = $request_state if defined($request_state); | ||
| 280 | return $self->{_request_state}; | ||
| 281 | } | ||
| 282 | |||
| 283 | |||
| 284 | # @return string | ||
| 285 | sub getRequestProtectionAccessToken | ||
| 286 | { | ||
| 287 | my( $self ) = @_; | ||
| 288 | return $self->{_request_protection_access_token} | ||
| 289 | } | ||
| 290 | |||
| 291 | ## | ||
| 292 | # @param string $request_protection_access_token | ||
| 293 | # @return void | ||
| 294 | # | ||
| 295 | sub setRequestProtectionAccessToken | ||
| 296 | { | ||
| 297 | my ( $self, $request_protection_access_token ) = @_; | ||
| 298 | $self->{_request_protection_access_token} = $request_protection_access_token if defined($request_protection_access_token); | ||
| 299 | return $self->{_request_protection_access_token}; | ||
| 300 | } | ||
| 301 | |||
| 302 | |||
| 303 | ## | ||
| 304 | # @return string | ||
| 305 | # | ||
| 306 | sub getResponseRpt | ||
| 307 | { | ||
| 308 | my( $self ) = @_; | ||
| 309 | $self->{_response_rpt} = $self->getResponseData()->{access_token}; | ||
| 310 | return $self->{_response_rpt}; | ||
| 311 | } | ||
| 312 | |||
| 313 | ## | ||
| 314 | # @return string | ||
| 315 | # | ||
| 316 | sub getResponseStatus | ||
| 317 | { | ||
| 318 | my( $self ) = @_; | ||
| 319 | $self->{_response_status} = $self->getResponseObject()->{status}; | ||
| 320 | return $self->{_response_status}; | ||
| 321 | } | ||
| 322 | |||
| 323 | ## | ||
| 324 | # @return string | ||
| 325 | # | ||
| 326 | sub getResponseError | ||
| 327 | { | ||
| 328 | my( $self ) = @_; | ||
| 329 | $self->{_response_error} = $self->getResponseData()->{error}; | ||
| 330 | return $self->{_response_error}; | ||
| 331 | } | ||
| 332 | |||
| 333 | ## | ||
| 334 | # @return string | ||
| 335 | # | ||
| 336 | sub getResponseTicket | ||
| 337 | { | ||
| 338 | my( $self ) = @_; | ||
| 339 | $self->{_response_ticket} = $self->getResponseData()->{details}->{ticket}; | ||
| 340 | return $self->{_response_ticket}; | ||
| 341 | } | ||
| 342 | |||
| 343 | ## | ||
| 344 | # Protocol command to oxd server | ||
| 345 | # @return void | ||
| 346 | # | ||
| 347 | sub setCommand | ||
| 348 | { | ||
| 349 | my ( $self ) = @_; | ||
| 350 | $self->{_command} = 'uma_rp_get_rpt'; | ||
| 351 | } | ||
| 352 | |||
| 353 | ## | ||
| 354 | # Protocol command to oxd to http server | ||
| 355 | # @return void | ||
| 356 | # | ||
| 357 | sub sethttpCommand | ||
| 358 | { | ||
| 359 | my ( $self ) = @_; | ||
| 360 | $self->{_httpcommand} = 'uma-rp-get-rpt'; | ||
| 361 | } | ||
| 362 | |||
| 363 | # Method: setParams | ||
| 364 | # This method sets the parameters for uma_rp_get_rpt command. | ||
| 365 | # This module uses `request` method of OxdClient module for sending request to oxd-server | ||
| 366 | # | ||
| 367 | # Parameters: | ||
| 368 | # | ||
| 369 | # string $oxd_id - (Required) oxd Id from Client registration | ||
| 370 | # | ||
| 371 | # string $ticket - (Required) Ticket from RS Check Access | ||
| 372 | # | ||
| 373 | # string $claim_token - (Optional) Claim Token | ||
| 374 | # | ||
| 375 | # string $claim_token_format - (Optional) Claim Token Format | ||
| 376 | # | ||
| 377 | # string $pct - (Optional) PCT | ||
| 378 | # | ||
| 379 | # string $rpt - (Optional) Request Party Token | ||
| 380 | # | ||
| 381 | # array $scope - (Optional) Scope | ||
| 382 | # | ||
| 383 | # string $state - (Optional) State returned from UMA_RP_GET_CLAIMS_GATHERING_URL | ||
| 384 | # | ||
| 385 | # string $protection_access_token - Protection Acccess Token. OPTIONAL for `oxd-server` but REQUIRED for `oxd-https-extension` | ||
| 386 | # | ||
| 387 | # Returns: | ||
| 388 | # void | ||
| 389 | # | ||
| 390 | # This module uses `getResponseObject` method of OxdClient module for getting response from oxd. | ||
| 391 | # | ||
| 392 | # *Success Response from getResponseObject:* | ||
| 393 | # --- Code | ||
| 394 | # { "status":"ok", "data":{ "access_token":"SSJHBSUSSJHVhjsgvhsgvshgsv", "token_type":"Bearer", "pct":"c2F2ZWRjb25zZW50", "upgraded":true } } | ||
| 395 | # --- | ||
| 396 | # | ||
| 397 | # *Needs Info Error Response from getResponseObject:* | ||
| 398 | # --- Code | ||
| 399 | # { "status": "error", "data": { "error": "need_info", "error_description": "The authorization server needs additional information in order to determine whether the client is authorized to have these permissions.", "details": { "error": "need_info", "ticket": "ZXJyb3JfZGV0YWlscw==", "required_claims": [{ "claim_token_format": [ "http://openid.net/specs/openid-connect-core-1_0.html#IDToken" ], "claim_type": "urn:oid:0.9.2342.19200300.100.1.3", "friendly_name": "email", "issuer": ["https://example.com/idp"], "name": "email23423453ou453" }], "redirect_user": "https://as.example.com/rqp_claims?id=2346576421" } } } | ||
| 400 | # --- | ||
| 401 | # | ||
| 402 | # *Invalid Ticket Error Response from getResponseObject:* | ||
| 403 | # --- Code | ||
| 404 | # { "status":"error", "data":{ "error":"invalid_ticket", "error_description":"Ticket is not valid (outdated or not present on Authorization Server)." } } | ||
| 405 | # --- | ||
| 406 | # | ||
| 407 | sub setParams | ||
| 408 | { | ||
| 409 | my ( $self, $params ) = @_; | ||
| 410 | my $paramsArray = { | ||
| 411 | "oxd_id" => $self->getRequestOxdId(), | ||
| 412 | "ticket" => $self->getRequestTicket(), | ||
| 413 | "claim_token" => $self->getRequestClaimToken(), | ||
| 414 | "claim_token_format" => $self->getRequestClaimTokenFormat(), | ||
| 415 | "pct" => $self->getRequestPCT(), | ||
| 416 | "rpt" => $self->getRequestRPT(), | ||
| 417 | "scope" => $self->getRequestScope(), | ||
| 418 | "state" => $self->getRequestState(), | ||
| 419 | "protection_access_token" => $self->getRequestProtectionAccessToken() | ||
| 420 | }; | ||
| 421 | $self->{_params} = $paramsArray; | ||
| 422 | return $self->{_params}; | ||
| 423 | } | ||
| 424 | |||
| 425 | 1; # this 1; is neccessary for our class to work |