| @@ 181-196 (lines=16) @@ | ||
| 178 | * @throws Exception\JSON |
|
| 179 | * @return string Token |
|
| 180 | */ |
|
| 181 | protected function token_encode($payload) |
|
| 182 | { |
|
| 183 | Log::instance()->debug('encode payload:'); |
|
| 184 | Log::instance()->debug(print_r($payload, true)); |
|
| 185 | try |
|
| 186 | { |
|
| 187 | $token = JWT::encode($payload, $this->own_private_key(), 'RS512'); |
|
| 188 | } |
|
| 189 | catch (\Exception $e) |
|
| 190 | { |
|
| 191 | Log::instance()->error($e->getMessage().PHP_EOL.$e->getTraceAsString()); |
|
| 192 | throw new Exception\JSON('unable to create JWT token', $e); |
|
| 193 | } |
|
| 194 | ||
| 195 | return $token; |
|
| 196 | } |
|
| 197 | ||
| 198 | /** |
|
| 199 | * Send request to UAPAY |
|
| @@ 131-147 (lines=17) @@ | ||
| 128 | * @throws Exception\Runtime |
|
| 129 | * @return array |
|
| 130 | */ |
|
| 131 | protected function token_decode($token) |
|
| 132 | { |
|
| 133 | try |
|
| 134 | { |
|
| 135 | $decoded = (array) JWT::decode($token, $this->uapay_public_key(), array('RS512')); |
|
| 136 | } |
|
| 137 | catch (\Exception $e) |
|
| 138 | { |
|
| 139 | Log::instance()->error($e->getMessage().PHP_EOL.$e->getTraceAsString()); |
|
| 140 | throw new Exception\JSON('unable to decode JWT token', $e); |
|
| 141 | } |
|
| 142 | ||
| 143 | Log::instance()->debug('decoded payload:'); |
|
| 144 | Log::instance()->debug(print_r($decoded, true)); |
|
| 145 | ||
| 146 | return $decoded; |
|
| 147 | } |
|
| 148 | ||
| 149 | /** |
|
| 150 | * Get status code |
|