do not use state parameter on auth code verification
[indieauth-openid.git] / src / phar-stub.php
1 <?php
2 /**
3  * Phar stub file for indieauth-openid. Handles startup of the .phar file.
4  */
5 if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) {
6     echo "Phar extension not avaiable\n";
7     exit(255);
8 }
9
10 $web = 'www/index.php';
11
12 /**
13  * Rewrite the HTTP request path to an internal file.
14  * Maps "" and "/" to "www/index.php".
15  *
16  * @param string $path Path from the browser, relative to the .phar
17  *
18  * @return string Internal path.
19  */
20 function rewritePath($path)
21 {
22     if ($path == '') {
23         //we need a / to get the relative links on index.php work
24         if (!isset($_SERVER['REQUEST_SCHEME'])) {
25             $_SERVER['REQUEST_SCHEME'] = 'http';
26         }
27         $url = $_SERVER['REQUEST_SCHEME'] . '://'
28             . $_SERVER['HTTP_HOST']
29             . preg_replace('/[?#].*$/', '', $_SERVER['REQUEST_URI'])
30             . '/';
31         header('Location: ' . $url);
32         exit(0);
33     } else if ($path == '/') {
34         return 'www/index.php';
35     }
36
37     if (substr($path, -4) == '.css') {
38         header('Expires: ' . date('r', time() + 86400 * 7));
39     }
40     return 'www' . $path;
41 }
42
43 if ($_SERVER['REQUEST_METHOD'] == 'HEAD') {
44     //work around https://bugs.php.net/bug.php?id=51918
45     header('IndieAuth: authorization_endpoint');
46     exit();
47 }
48
49 set_include_path(
50     'phar://' . __FILE__
51     . PATH_SEPARATOR . 'phar://' . __FILE__ . '/lib/'
52 );
53 Phar::webPhar(null, $web, null, array(), 'rewritePath');
54
55 //TODO: implement CLI setup check
56 echo "indieauth-openid can only be used in the browser\n";
57 exit(1);
58 __HALT_COMPILER();
59 ?>