| 1 | #!/usr/bin/perl | ||
| 2 | # IntrospectAccessToken.pm, a number as an object | ||
| 3 | |||
| 4 | |||
| 5 | ## | ||
| 6 | # Gluu-oxd-library | ||
| 7 | # | ||
| 8 | # An open source application library for Perl | ||
| 9 | # | ||
| 10 | # This content is released under the MIT License (MIT) | ||
| 11 | # | ||
| 12 | # Copyright (c) 2018, Gluu inc, USA, Austin | ||
| 13 | # | ||
| 14 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 15 | # of this software and associated documentation files (the "Software"), to deal | ||
| 16 | # in the Software without restriction, including without limitation the rights | ||
| 17 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 18 | # copies of the Software, and to permit persons to whom the Software is | ||
| 19 | # furnished to do so, subject to the following conditions: | ||
| 20 | # | ||
| 21 | # The above copyright notice and this permission notice shall be included in | ||
| 22 | # all copies or substantial portions of the Software. | ||
| 23 | # | ||
| 24 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 25 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 26 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 27 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 28 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 29 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 30 | # THE SOFTWARE. | ||
| 31 | # | ||
| 32 | # @package Gluu-oxd-library | ||
| 33 | # @version 3.1.3 | ||
| 34 | # @author Sobhan Panda | ||
| 35 | # @author_email sobhan@centroxy.com | ||
| 36 | # @copyright Copyright (c) 2018, Gluu inc federation (https://gluu.org/) | ||
| 37 | # @license http://opensource.org/licenses/MIT MIT License | ||
| 38 | # @link https://gluu.org/ | ||
| 39 | # @since Version 3.1.3 | ||
| 40 | # @filesource | ||
| 41 | # | ||
| 42 | #/ | ||
| 43 | |||
| 44 | package IntrospectAccessToken; # This is the "Class" | ||
| 45 | use OxdPackages::OxdClient; | ||
| 46 | use base qw(OxdClient Class::Accessor); | ||
| 47 | use strict; | ||
| 48 | our @ISA = qw(OxdClient); # inherits from OxdClient | ||
| 49 | |||
| 50 | use vars qw($VERSION); | ||
| 51 | $VERSION = '0.01'; | ||
| 52 | |||
| 53 | sub new { | ||
| 54 | my $class = shift; | ||
| 55 | my $self = { | ||
| 56 | |||
| 57 | # @var string $request_oxd_id This parameter you must get after registration site in gluu-server | ||
| 58 | |||
| 59 | _request_oxd_id => shift, | ||
| 60 | |||
| 61 | # @var string $request_access_token This parameter you must get after using get_token_code or get_client_token class | ||
| 62 | |||
| 63 | _request_access_token => shift, | ||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | # Response parameter from oxd-server | ||
| 68 | # It shows whether the token is active or not | ||
| 69 | # | ||
| 70 | # @var string $response_active | ||
| 71 | |||
| 72 | _response_active => shift, | ||
| 73 | |||
| 74 | # Response parameter from oxd-server | ||
| 75 | # Shows the registered client_id to whom the token is assigned | ||
| 76 | # | ||
| 77 | # @var string $response_client_id | ||
| 78 | |||
| 79 | _response_client_id => shift, | ||
| 80 | |||
| 81 | |||
| 82 | # Response parameter from oxd-server | ||
| 83 | # Shows the user name to whom the token is assigned | ||
| 84 | # | ||
| 85 | # @var string $response_user_name | ||
| 86 | |||
| 87 | _response_user_name => shift, | ||
| 88 | |||
| 89 | |||
| 90 | }; | ||
| 91 | # Print all the values just for clarification. | ||
| 92 | bless $self, $class; | ||
| 93 | |||
| 94 | return $self; | ||
| 95 | } | ||
| 96 | |||
| 97 | |||
| 98 | # @return string | ||
| 99 | |||
| 100 | sub getRequestOxdId | ||
| 101 | { | ||
| 102 | my( $self ) = @_; | ||
| 103 | return $self->{_request_oxd_id}; | ||
| 104 | } | ||
| 105 | |||
| 106 | |||
| 107 | # @param string $request_oxd_id | ||
| 108 | # @return void | ||
| 109 | |||
| 110 | sub setRequestOxdId | ||
| 111 | { | ||
| 112 | my ( $self, $request_oxd_id ) = @_; | ||
| 113 | $self->{_request_oxd_id} = $request_oxd_id if defined($request_oxd_id); | ||
| 114 | return $self->{_request_oxd_id}; | ||
| 115 | } | ||
| 116 | |||
| 117 | |||
| 118 | # @return string | ||
| 119 | |||
| 120 | sub getRequestAccessToken | ||
| 121 | { | ||
| 122 | my( $self ) = @_; | ||
| 123 | return $self->{_request_access_token}; | ||
| 124 | } | ||
| 125 | |||
| 126 | |||
| 127 | # @param string $request_access_token | ||
| 128 | # @return void | ||
| 129 | |||
| 130 | sub setRequestAccessToken | ||
| 131 | { | ||
| 132 | my ( $self, $request_access_token ) = @_; | ||
| 133 | $self->{_request_access_token} = $request_access_token if defined($request_access_token); | ||
| 134 | return $self->{_request_access_token}; | ||
| 135 | } | ||
| 136 | |||
| 137 | |||
| 138 | # @return string | ||
| 139 | |||
| 140 | sub getResponseActive | ||
| 141 | { | ||
| 142 | my( $self ) = @_; | ||
| 143 | $self->{_response_active} = $self->getResponseData()->{active}; | ||
| 144 | return $self->{_response_active}; | ||
| 145 | } | ||
| 146 | |||
| 147 | |||
| 148 | # @return string | ||
| 149 | |||
| 150 | sub getResponseClientId | ||
| 151 | { | ||
| 152 | my( $self ) = @_; | ||
| 153 | $self->{_response_client_id} = $self->getResponseData()->{client_id}; | ||
| 154 | return $self->{_response_client_id}; | ||
| 155 | } | ||
| 156 | |||
| 157 | |||
| 158 | # @return string | ||
| 159 | |||
| 160 | sub getResponseUserName | ||
| 161 | { | ||
| 162 | my( $self ) = @_; | ||
| 163 | $self->{_response_user_name} = $self->getResponseData()->{user_name}; | ||
| 164 | return $self->{_response_user_name}; | ||
| 165 | } | ||
| 166 | |||
| 167 | |||
| 168 | # Protocol command for oxd server | ||
| 169 | # @return void | ||
| 170 | |||
| 171 | sub setCommand | ||
| 172 | { | ||
| 173 | my ( $self, $command ) = @_; | ||
| 174 | $self->{_command} = 'introspect_access_token'; | ||
| 175 | return $self->{_command}; | ||
| 176 | } | ||
| 177 | |||
| 178 | # Protocol command for oxd-https-extension | ||
| 179 | # @return void | ||
| 180 | |||
| 181 | sub sethttpCommand | ||
| 182 | { | ||
| 183 | my ( $self, $httpCommand ) = @_; | ||
| 184 | $self->{_httpcommand} = 'introspect-access-token'; | ||
| 185 | return $self->{_httpcommand}; | ||
| 186 | } | ||
| 187 | |||
| 188 | # Method: setParams | ||
| 189 | # This method sets the parameters for introspect_access_token command. | ||
| 190 | # This module uses `request` method of OxdClient module for sending request to oxd-server | ||
| 191 | # | ||
| 192 | # Parameters: | ||
| 193 | # | ||
| 194 | # string $oxd_id - (Required) oxd Id from Client registration | ||
| 195 | # | ||
| 196 | # string $access_token - (Required) Acccess Token | ||
| 197 | # | ||
| 198 | # Returns: | ||
| 199 | # void | ||
| 200 | # | ||
| 201 | # This module uses `getResponseObject` method of OxdClient module for getting response from oxd. | ||
| 202 | # | ||
| 203 | # *Example response from getResponseObject:* | ||
| 204 | # --- Code | ||
| 205 | # { "status": "ok", "data": { "active": true, "scopes": ["openid"], "client_id": "@!DEEA.B5F2.074F.4295!0001!5BE0.4886!0008!C314.0AC7.C908.77D0", "username": null, "token_type": "bearer", "exp": 1517391098, "iat": 1517390798, "sub": null, "aud": "@!DEEA.B5F2.074F.4295!0001!5BE0.4886!0008!C314.0AC7.C908.77D0", "iss": "https://idp.gluu.org", "jti": null, "acr_values": null } } | ||
| 206 | # --- | ||
| 207 | # | ||
| 208 | sub setParams | ||
| 209 | { | ||
| 210 | my ( $self, $params ) = @_; | ||
| 211 | my $paramsArray = { | ||
| 212 | "oxd_id" => $self->getRequestOxdId(), | ||
| 213 | "access_token" => $self->getRequestAccessToken() | ||
| 214 | }; | ||
| 215 | |||
| 216 | $self->{_params} = $paramsArray; | ||
| 217 | return $self->{_params}; | ||
| 218 | } | ||
| 219 | |||
| 220 | |||
| 221 | 1; # this 1; is neccessary for our class to work |