-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedirectException.php
45 lines (39 loc) · 1.23 KB
/
RedirectException.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* @link https://github.com/borodulin/yii2-oauth-server
* @copyright Copyright (c) 2015 Andrey Borodulin
* @license https://github.com/borodulin/yii2-oauth-server/blob/master/LICENSE
*/
namespace yuncms\oauth2;
use Yii;
/**
*
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.1
*
* @author Andrey Borodulin
*
*/
class RedirectException extends Exception
{
/**
* @param string $redirect_uri
* @param string $error_description (optional)
* @param string $error A single error code
* @param string $state Cross-Site Request Forgery
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.1.2.1
*/
public function __construct($redirect_uri, $error_description = null, $error = self::INVALID_REQUEST, $state = null)
{
parent::__construct($error_description, $error);
$query = ['error' => $error];
if ($error_description) {
$query['error_description'] = $error_description;
}
if ($state) {
$query['state'] = $state;
}
Yii::$app->response->redirect(http_build_url($redirect_uri, [
'query' => http_build_query($query)
], HTTP_URL_REPLACE | HTTP_URL_JOIN_QUERY));
}
}