| 1 | #!/usr/bin/perl | ||
| 2 | # GetAccessTokenByRefreshToken.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) 2017, 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.0 | ||
| 34 | # @author Sobhan Panda | ||
| 35 | # @author_email sobhan@centroxy.com | ||
| 36 | # @copyright Copyright (c) 2017, 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.0 | ||
| 40 | # @filesource | ||
| 41 | # | ||
| 42 | #/ | ||
| 43 | |||
| 44 | package GetAccessTokenByRefreshToken; # 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_refresh_token This parameter you must get after using get_token_code class | ||
| 62 | |||
| 63 | _request_refresh_token => shift, | ||
| 64 | |||
| 65 | # @var string $request_scope | ||
| 66 | |||
| 67 | _request_scopes => shift, | ||
| 68 | |||
| 69 | # @var string $request_protection_access_token To protect the command with access token | ||
| 70 | _request_protection_access_token => shift, | ||
| 71 | |||
| 72 | |||
| 73 | # Response parameter from oxd-server | ||
| 74 | # It need to using for get_user_info and logout classes | ||
| 75 | # | ||
| 76 | # @var string $response_access_token | ||
| 77 | |||
| 78 | _response_access_token => shift, | ||
| 79 | |||
| 80 | # Response parameter from oxd-server | ||
| 81 | # Showing user expires time | ||
| 82 | # | ||
| 83 | # @var string $response_expires_in | ||
| 84 | |||
| 85 | _response_expires_in => shift, | ||
| 86 | |||
| 87 | |||
| 88 | # Response parameter from oxd-server | ||
| 89 | # Showing user claimses and data | ||
| 90 | # | ||
| 91 | # @var string $response_refresh_token | ||
| 92 | |||
| 93 | _response_refresh_token => shift, | ||
| 94 | |||
| 95 | |||
| 96 | }; | ||
| 97 | # Print all the values just for clarification. | ||
| 98 | bless $self, $class; | ||
| 99 | |||
| 100 | return $self; | ||
| 101 | } | ||
| 102 | |||
| 103 | |||
| 104 | # @return string | ||
| 105 | |||
| 106 | sub getRequestScopes | ||
| 107 | { | ||
| 108 | my( $self ) = @_; | ||
| 109 | return $self->{_request_scopes}; | ||
| 110 | } | ||
| 111 | |||
| 112 | |||
| 113 | # @param string $request_scopes | ||
| 114 | # @return void | ||
| 115 | |||
| 116 | sub setRequestScopes | ||
| 117 | { | ||
| 118 | my ( $self, $request_scopes ) = @_; | ||
| 119 | $self->{_request_scopes} = $request_scopes if defined($request_scopes); | ||
| 120 | return $self->{_request_scopes}; | ||
| 121 | } | ||
| 122 | |||
| 123 | |||
| 124 | # @return string | ||
| 125 | |||
| 126 | sub getRequestOxdId | ||
| 127 | { | ||
| 128 | my( $self ) = @_; | ||
| 129 | return $self->{_request_oxd_id}; | ||
| 130 | } | ||
| 131 | |||
| 132 | |||
| 133 | # @param string $request_oxd_id | ||
| 134 | # @return void | ||
| 135 | |||
| 136 | sub setRequestOxdId | ||
| 137 | { | ||
| 138 | my ( $self, $request_oxd_id ) = @_; | ||
| 139 | $self->{_request_oxd_id} = $request_oxd_id if defined($request_oxd_id); | ||
| 140 | return $self->{_request_oxd_id}; | ||
| 141 | } | ||
| 142 | |||
| 143 | |||
| 144 | # @return string | ||
| 145 | |||
| 146 | sub getRequestRefreshToken | ||
| 147 | { | ||
| 148 | my( $self ) = @_; | ||
| 149 | return $self->{_request_refresh_token}; | ||
| 150 | } | ||
| 151 | |||
| 152 | |||
| 153 | # @param string $request_refresh_token | ||
| 154 | # @return void | ||
| 155 | |||
| 156 | sub setRequestRefreshToken | ||
| 157 | { | ||
| 158 | my ( $self, $request_refresh_token ) = @_; | ||
| 159 | $self->{_request_refresh_token} = $request_refresh_token if defined($request_refresh_token); | ||
| 160 | return $self->{_request_refresh_token}; | ||
| 161 | } | ||
| 162 | |||
| 163 | |||
| 164 | # @return array | ||
| 165 | sub getRequestProtectionAccessToken | ||
| 166 | { | ||
| 167 | my( $self ) = @_; | ||
| 168 | return $self->{_request_protection_access_token}; | ||
| 169 | } | ||
| 170 | |||
| 171 | |||
| 172 | # @param array $request_protection_access_token | ||
| 173 | # @return void | ||
| 174 | sub setRequestProtectionAccessToken | ||
| 175 | { | ||
| 176 | my ( $self, $request_protection_access_token ) = @_; | ||
| 177 | $self->{_request_protection_access_token} = $request_protection_access_token if defined($request_protection_access_token); | ||
| 178 | return $self->{_request_protection_access_token}; | ||
| 179 | } | ||
| 180 | |||
| 181 | |||
| 182 | # @return string | ||
| 183 | |||
| 184 | sub getResponseAccessToken | ||
| 185 | { | ||
| 186 | my( $self ) = @_; | ||
| 187 | $self->{_response_access_token} = $self->getResponseData()->{access_token}; | ||
| 188 | return $self->{_response_access_token}; | ||
| 189 | } | ||
| 190 | |||
| 191 | |||
| 192 | # @return string | ||
| 193 | |||
| 194 | sub getResponseExpiresIn | ||
| 195 | { | ||
| 196 | my( $self ) = @_; | ||
| 197 | $self->{_response_expires_in} = $self->getResponseData()->{expires_in}; | ||
| 198 | return $self->{_response_expires_in}; | ||
| 199 | } | ||
| 200 | |||
| 201 | |||
| 202 | # @return string | ||
| 203 | |||
| 204 | sub getResponseRefreshToken | ||
| 205 | { | ||
| 206 | my( $self ) = @_; | ||
| 207 | $self->{_response_refresh_token} = $self->getResponseData()->{refresh_token}; | ||
| 208 | return $self->{_response_refresh_token}; | ||
| 209 | } | ||
| 210 | |||
| 211 | |||
| 212 | # Protocol command to oxd server | ||
| 213 | # @return void | ||
| 214 | |||
| 215 | sub setCommand | ||
| 216 | { | ||
| 217 | my ( $self, $command ) = @_; | ||
| 218 | $self->{_command} = 'get_access_token_by_refresh_token'; | ||
| 219 | return $self->{_command}; | ||
| 220 | } | ||
| 221 | |||
| 222 | # Protocol command to oXD to http server | ||
| 223 | # @return void | ||
| 224 | |||
| 225 | sub sethttpCommand | ||
| 226 | { | ||
| 227 | my ( $self, $httpCommand ) = @_; | ||
| 228 | $self->{_httpcommand} = 'get-access-token-by-refresh-token'; | ||
| 229 | return $self->{_httpcommand}; | ||
| 230 | } | ||
| 231 | |||
| 232 | # Protocol parameter to oxd server | ||
| 233 | # @return void | ||
| 234 | |||
| 235 | sub setParams | ||
| 236 | { | ||
| 237 | my ( $self, $params ) = @_; | ||
| 238 | my $paramsArray = { | ||
| 239 | "oxd_id" => $self->getRequestOxdId(), | ||
| 240 | "refresh_token" => $self->getRequestRefreshToken(), | ||
| 241 | "scope" => $self->getRequestScopes(), | ||
| 242 | "protection_access_token"=> $self->getRequestProtectionAccessToken() | ||
| 243 | }; | ||
| 244 | #use Data::Dumper; | ||
| 245 | #print Dumper( $paramsArray ); | ||
| 246 | $self->{_params} = $paramsArray; | ||
| 247 | return $self->{_params}; | ||
| 248 | } | ||
| 249 | |||
| 250 | |||
| 251 | 1; # this 1; is neccessary for our class to work |