source: sandbox/2.4.1-3/prototype/library/oauth2/lib/OAuth2RedirectException.php @ 6351

Revision 6351, 2.6 KB checked in by gustavo, 12 years ago (diff)

Ticket #2768 - Melhorias na inserção de destinatários na criacao de mensagem

  • Property svn:executable set to *
Line 
1<?php
2
3/**
4 * Redirect the end-user's user agent with error message.
5 *
6 * @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.1
7 *
8 * @ingroup oauth2_error
9 */
10class OAuth2RedirectException extends OAuth2ServerException {
11       
12        protected $redirectUri;
13
14        /**
15         * @param $redirect_uri
16         * An absolute URI to which the authorization server will redirect the
17         * user-agent to when the end-user authorization step is completed.
18         * @param $error
19         * A single error code as described in Section 4.1.2.1
20         * @param $error_description
21         * (optional) A human-readable text providing additional information,
22         * used to assist in the understanding and resolution of the error
23         * occurred.
24         * @param $state
25         * (optional) REQUIRED if the "state" parameter was present in the client
26         * authorization request. Set to the exact value received from the client.
27         *
28         * @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.1.2.1
29         *
30         * @ingroup oauth2_error
31         */
32        public function __construct($redirect_uri, $error, $error_description = NULL, $state = NULL) {
33                parent::__construct(OAuth2::HTTP_FOUND, $error, $error_description);
34               
35                $this->redirectUri = $redirect_uri;
36                if ($state) {
37                        $this->errorData['state'] = $state;
38                }
39       
40        }
41
42        /**
43         * Redirect the user agent.
44         *
45         * @ingroup oauth2_section_4
46         */
47        protected function sendHeaders() {
48                $params = array('query' => $this->errorData);
49                header("Location: " . $this->buildUri($this->redirectUri, $params));
50                exit(); // No point in printing out data if we're redirecting
51        }
52
53        /**
54         * Build the absolute URI based on supplied URI and parameters.
55         *
56         * @param $uri
57         * An absolute URI.
58         * @param $params
59         * Parameters to be append as GET.
60         *
61         * @return
62         * An absolute URI with supplied parameters.
63         *
64         * @ingroup oauth2_section_4
65         */
66        protected function buildUri($uri, $params) {
67                $parse_url = parse_url($uri);
68               
69                // Add our params to the parsed uri
70                foreach ( $params as $k => $v ) {
71                        if (isset($parse_url[$k]))
72                                $parse_url[$k] .= "&" . http_build_query($v);
73                        else
74                                $parse_url[$k] = http_build_query($v);
75                }
76               
77                // Put humpty dumpty back together
78                return ((isset($parse_url["scheme"])) ? $parse_url["scheme"] . "://" : "") . ((isset($parse_url["user"])) ? $parse_url["user"] . ((isset($parse_url["pass"])) ? ":" . $parse_url["pass"] : "") . "@" : "") . ((isset($parse_url["host"])) ? $parse_url["host"] : "") . ((isset($parse_url["port"])) ? ":" . $parse_url["port"] : "") . ((isset($parse_url["path"])) ? $parse_url["path"] : "") . ((isset($parse_url["query"])) ? "?" . $parse_url["query"] : "") . ((isset($parse_url["fragment"])) ? "#" . $parse_url["fragment"] : "");
79        }
80}
Note: See TracBrowser for help on using the repository browser.