@@ -230,84 +230,84 @@ |
||
| 230 | 230 | return; |
| 231 | 231 | } |
| 232 | 232 | switch ($_GET['response_type']) { |
| 233 | - case 'code': |
|
| 234 | - $Response->redirect( |
|
| 235 | - http_build_url( |
|
| 236 | - urldecode($redirect_uri), |
|
| 237 | - [ |
|
| 238 | - 'code' => $code, |
|
| 239 | - 'state' => isset($_GET['state']) ? $_GET['state'] : false |
|
| 240 | - ] |
|
| 241 | - ), |
|
| 242 | - 302 |
|
| 243 | - ); |
|
| 244 | - $Page->Content = ''; |
|
| 245 | - return; |
|
| 246 | - case 'token': |
|
| 247 | - $token_data = $OAuth2->get_code($code, $client['id'], $client['secret'], $redirect_uri); |
|
| 248 | - if ($token_data) { |
|
| 249 | - unset($token_data['refresh_token']); |
|
| 233 | + case 'code': |
|
| 250 | 234 | $Response->redirect( |
| 251 | - uri_for_token( |
|
| 252 | - http_build_url( |
|
| 253 | - urldecode($redirect_uri), |
|
| 254 | - array_merge( |
|
| 255 | - $token_data, |
|
| 256 | - [ |
|
| 257 | - 'state' => isset($_GET['state']) ? $_GET['state'] : false |
|
| 258 | - ] |
|
| 259 | - ) |
|
| 260 | - ) |
|
| 235 | + http_build_url( |
|
| 236 | + urldecode($redirect_uri), |
|
| 237 | + [ |
|
| 238 | + 'code' => $code, |
|
| 239 | + 'state' => isset($_GET['state']) ? $_GET['state'] : false |
|
| 240 | + ] |
|
| 261 | 241 | ), |
| 262 | 242 | 302 |
| 263 | 243 | ); |
| 264 | 244 | $Page->Content = ''; |
| 265 | 245 | return; |
| 266 | - } else { |
|
| 267 | - error_redirect('server_error', "Server can't get token data, try later"); |
|
| 268 | - return; |
|
| 269 | - } |
|
| 270 | - case 'guest_token': |
|
| 271 | - $Response |
|
| 272 | - ->header('cache-control', 'no-store') |
|
| 273 | - ->header('pragma', 'no-cache'); |
|
| 274 | - if ($User->user()) { |
|
| 275 | - $e = new ExitException( |
|
| 276 | - [ |
|
| 277 | - 'access_denied', |
|
| 278 | - 'Only guests, not users allowed to access this response_type' |
|
| 279 | - ], |
|
| 280 | - 403 |
|
| 281 | - ); |
|
| 282 | - $e->setJson(); |
|
| 283 | - throw $e; |
|
| 284 | - } |
|
| 285 | - $code = $OAuth2->add_code($client['id'], 'token', urldecode($_GET['redirect_uri'])); |
|
| 286 | - if (!$code) { |
|
| 287 | - $e = new ExitException( |
|
| 288 | - [ |
|
| 289 | - 'server_error', |
|
| 290 | - "Server can't generate code, try later" |
|
| 291 | - ], |
|
| 292 | - 500 |
|
| 293 | - ); |
|
| 294 | - $e->setJson(); |
|
| 295 | - throw $e; |
|
| 296 | - } |
|
| 297 | - $token_data = $OAuth2->get_code($code, $client['id'], $client['secret'], urldecode($_GET['redirect_uri'])); |
|
| 298 | - if ($token_data) { |
|
| 299 | - unset($token_data['refresh_token']); |
|
| 300 | - $Page->json($token_data); |
|
| 301 | - return; |
|
| 302 | - } else { |
|
| 303 | - $e = new ExitException( |
|
| 304 | - [ |
|
| 305 | - 'server_error', |
|
| 306 | - "Server can't get token data, try later" |
|
| 307 | - ], |
|
| 308 | - 500 |
|
| 309 | - ); |
|
| 310 | - $e->setJson(); |
|
| 311 | - throw $e; |
|
| 312 | - } |
|
| 246 | + case 'token': |
|
| 247 | + $token_data = $OAuth2->get_code($code, $client['id'], $client['secret'], $redirect_uri); |
|
| 248 | + if ($token_data) { |
|
| 249 | + unset($token_data['refresh_token']); |
|
| 250 | + $Response->redirect( |
|
| 251 | + uri_for_token( |
|
| 252 | + http_build_url( |
|
| 253 | + urldecode($redirect_uri), |
|
| 254 | + array_merge( |
|
| 255 | + $token_data, |
|
| 256 | + [ |
|
| 257 | + 'state' => isset($_GET['state']) ? $_GET['state'] : false |
|
| 258 | + ] |
|
| 259 | + ) |
|
| 260 | + ) |
|
| 261 | + ), |
|
| 262 | + 302 |
|
| 263 | + ); |
|
| 264 | + $Page->Content = ''; |
|
| 265 | + return; |
|
| 266 | + } else { |
|
| 267 | + error_redirect('server_error', "Server can't get token data, try later"); |
|
| 268 | + return; |
|
| 269 | + } |
|
| 270 | + case 'guest_token': |
|
| 271 | + $Response |
|
| 272 | + ->header('cache-control', 'no-store') |
|
| 273 | + ->header('pragma', 'no-cache'); |
|
| 274 | + if ($User->user()) { |
|
| 275 | + $e = new ExitException( |
|
| 276 | + [ |
|
| 277 | + 'access_denied', |
|
| 278 | + 'Only guests, not users allowed to access this response_type' |
|
| 279 | + ], |
|
| 280 | + 403 |
|
| 281 | + ); |
|
| 282 | + $e->setJson(); |
|
| 283 | + throw $e; |
|
| 284 | + } |
|
| 285 | + $code = $OAuth2->add_code($client['id'], 'token', urldecode($_GET['redirect_uri'])); |
|
| 286 | + if (!$code) { |
|
| 287 | + $e = new ExitException( |
|
| 288 | + [ |
|
| 289 | + 'server_error', |
|
| 290 | + "Server can't generate code, try later" |
|
| 291 | + ], |
|
| 292 | + 500 |
|
| 293 | + ); |
|
| 294 | + $e->setJson(); |
|
| 295 | + throw $e; |
|
| 296 | + } |
|
| 297 | + $token_data = $OAuth2->get_code($code, $client['id'], $client['secret'], urldecode($_GET['redirect_uri'])); |
|
| 298 | + if ($token_data) { |
|
| 299 | + unset($token_data['refresh_token']); |
|
| 300 | + $Page->json($token_data); |
|
| 301 | + return; |
|
| 302 | + } else { |
|
| 303 | + $e = new ExitException( |
|
| 304 | + [ |
|
| 305 | + 'server_error', |
|
| 306 | + "Server can't get token data, try later" |
|
| 307 | + ], |
|
| 308 | + 500 |
|
| 309 | + ); |
|
| 310 | + $e->setJson(); |
|
| 311 | + throw $e; |
|
| 312 | + } |
|
| 313 | 313 | } |