-data/tokens.sq3
-README.html
+/config.php
+/data/tokens.sq3
+/dist/
+/lib/
+/README.html
Setup
=====
+0. Install dependencies
1. Setup your webserver: make ``www/`` the root (document) directory of the
new virtual host
2. Make ``data/`` world-writable (or at least writable by the web server)
<link rel="authorization_endpoint" href="http://indieauth-openid.example.org/" />
+Configuration
+=============
+A sqlite file ``data/tokens.sq3`` is created by indieauth-openid.
+To configure that path, copy ``config.php.dist`` to ``config.php`` and
+adjust it.
+
+If you're using the ``.phar`` file, append ``.config.php`` to the full
+file name - e.g. ``indieauth-openid-0.1.0.phar.config.php``.
+
+
============
Dependencies
============
* OpenID
+Installation
+============
+Install the dependencies::
+
+ $ pear install net_url2-2.2.1
+ $ pear install openid-alpha
+
+
=======
License
=======
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<project name="indieauth-openid" default="phar" basedir=".">
+ <!--
+ indieauth-openid phing build file.
+ -->
+ <property name="version" value="0.1.0" />
+ <property name="stability" value="beta" />
+ <property name="libdir" value="${phing.dir}/lib"/>
+
+ <property name="pharfile" value="${phing.project.name}-${version}.phar" />
+
+ <property name="pharpath" value="${phing.dir}/dist/${pharfile}" />
+
+ <fileset id="fs.phar" dir="${phing.dir}">
+ <include name="lib/**"/>
+ <include name="www/**"/>
+
+ <include name="ChangeLog"/>
+ <include name="README.rst"/>
+
+ <exclude name="**/.git/"/>
+ <exclude name="**/.gitignore/"/>
+ </fileset>
+
+ <target name="phar" depends="preparedirs,collectdeps"
+ description="Create phar file for release"
+ >
+ <delete file="${pharpath}"/>
+ <pharpackage basedir="${phing.dir}"
+ destfile="${pharpath}"
+ stub="${phing.dir}/src/phar-stub.php"
+ alias="phorkie.phar"
+ >
+ <fileset refid="fs.phar"/>
+ </pharpackage>
+
+ <exec executable="bzip2" dir="${phing.dir}/dist">
+ <arg value="-kf"/>
+ <arg file="${pharpath}"/>
+ </exec>
+ </target>
+
+
+ <target name="collectdeps" description="Copy package dependencies to lib/">
+ <delete dir="${libdir}"/>
+ <mkdir dir="${libdir}"/>
+
+ <!-- requires phing >= 2.8.0 -->
+ <copy todir="${libdir}">
+ <pearPackageFileset package="pear.php.net/Cache_Lite"/><!-- OpenID -->
+ <pearPackageFileset package="pear.php.net/Crypt_DiffieHellman"/><!-- OpenID -->
+ <pearPackageFileset package="pear.php.net/HTTP_Request2"/><!-- OpenID -->
+ <pearPackageFileset package="pear.php.net/Net_URL2"/>
+ <pearPackageFileset package="pear.php.net/OpenID"/>
+ <pearPackageFileset package="pear.php.net/PEAR">
+ <include name="PEAR/Exception.php"/>
+ <include name="PEAR.php"/>
+ </pearPackageFileset>
+ <pearPackageFileset package="pear.php.net/Services_Yadis"/><!-- OpenID -->
+ <pearPackageFileset package="pear.php.net/Validate"/><!-- OpenID (Yadis) -->
+ </copy>
+ </target>
+
+ <target name="preparedirs">
+ <mkdir dir="dist" />
+ </target>
+</project>
--- /dev/null
+<?php
+//copy this to config.php and adjust it to your liking
+// when using the .phar, append ".config.php" to the phar file name
+$dsn = 'sqlite:/tmp/file.sq3';
+?>
--- /dev/null
+<?php
+/**
+ * Phar stub file for indieauth-openid. Handles startup of the .phar file.
+ */
+if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) {
+ echo "Phar extension not avaiable\n";
+ exit(255);
+}
+
+$web = 'www/index.php';
+
+/**
+ * Rewrite the HTTP request path to an internal file.
+ * Maps "" and "/" to "www/index.php".
+ *
+ * @param string $path Path from the browser, relative to the .phar
+ *
+ * @return string Internal path.
+ */
+function rewritePath($path)
+{
+ if ($path == '') {
+ //we need a / to get the relative links on index.php work
+ if (!isset($_SERVER['REQUEST_SCHEME'])) {
+ $_SERVER['REQUEST_SCHEME'] = 'http';
+ }
+ $url = $_SERVER['REQUEST_SCHEME'] . '://'
+ . $_SERVER['HTTP_HOST']
+ . preg_replace('/[?#].*$/', '', $_SERVER['REQUEST_URI'])
+ . '/';
+ header('Location: ' . $url);
+ exit(0);
+ } else if ($path == '/') {
+ return 'www/index.php';
+ }
+
+ if (substr($path, -4) == '.css') {
+ header('Expires: ' . date('r', time() + 86400 * 7));
+ }
+ return 'www' . $path;
+}
+
+if ($_SERVER['REQUEST_METHOD'] == 'HEAD') {
+ //work around https://bugs.php.net/bug.php?id=51918
+ header('IndieAuth: authorization_endpoint');
+ exit();
+}
+
+set_include_path(
+ 'phar://' . __FILE__
+ . PATH_SEPARATOR . 'phar://' . __FILE__ . '/lib/'
+);
+Phar::webPhar(null, $web, null, array(), 'rewritePath');
+
+//TODO: implement CLI setup check
+echo "indieauth-openid can only be used in the browser\n";
+exit(1);
+__HALT_COMPILER();
+?>
} else {
$prot = 'http';
}
-$epUrl = $prot . '://' . $_SERVER['HTTP_HOST'] . '/';
+$epUrl = $prot . '://' . $_SERVER['HTTP_HOST'] . '/';
+if (Phar::running()) {
+ $epUrl .= ltrim($_SERVER['SCRIPT_NAME'], '/') . '/';
+}
$hepUrl = htmlspecialchars($epUrl);
?>
function loadDb()
{
- $db = new PDO('sqlite:' . __DIR__ . '/../data/tokens.sq3');
+ $pharFile = \Phar::running();
+ if ($pharFile == '') {
+ $dsn = 'sqlite:' . __DIR__ . '/../data/tokens.sq3';
+ $cfgFilePath = __DIR__ . '/config.php';
+ } else {
+ //remove phar:// from the path
+ $dir = dirname(substr($pharFile, 7)) . '/';
+ $dsn = 'sqlite:' . $dir . '/tokens.sq3';
+ $cfgFilePath = substr($pharFile, 7) . '.config.php';
+ }
+ //allow overriding DSN
+ if (file_exists($cfgFilePath)) {
+ include $cfgFilePath;
+ }
+
+ $db = new PDO($dsn);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec("CREATE TABLE IF NOT EXISTS authtokens(
code TEXT,
}
} catch (OpenID_Exception $e) {
error('Error verifying OpenID login: ' . $e->getMessage());
+ } catch (Exception $e) {
+ error(get_class($e) . ': ' . $e->getMessage());
}
}
exit(0);
} catch (OpenID_Exception $e) {
error('OpenID error: ' . $e->getMessage());
+ } catch (Exception $e) {
+ error(get_class($e) . ': ' . $e->getMessage());
}
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$redirect_uri = verifyUrlParameter($_POST, 'redirect_uri');