Skip to content

Instantly share code, notes, and snippets.

@donpdonp
Last active July 8, 2018 15:39
Show Gist options
  • Save donpdonp/d137a1d2aafce008c8ab to your computer and use it in GitHub Desktop.
Save donpdonp/d137a1d2aafce008c8ab to your computer and use it in GitHub Desktop.
indieauth minimal html/php

Replace the URLs in the .php file with your domain name, success, and error pages.

Add this HTML to present a login form.

<form action="https://indieauth.com/auth" method="get">
  <label for="indie_auth_url">Web Address:</label>
  <input id="indie_auth_url" type="text" name="me" placeholder="yourdomain.com" />
  <p><button type="submit">Sign In</button></p>
  <input type="hidden" name="client_id" value="https://example.org/" />
  <input type="hidden" name="redirect_uri" value="https://example.org/indieauth.php" />
</form>
// callback from indieauth
$home = "http://example.org";
$fields = array("code"=>$_GET["token"],
"redirect_uri" => $home."/auth.php");
$ch = curl_init();
$indieauth = "https://indieauth.com/auth";
curl_setopt($ch,CURLOPT_URL, $indieauth);
curl_setopt($ch,CURLOPT_POST, True);
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($status == 200) {
parse_str($result, $answer);
if($answer['me']) {
$secret = md5(rand());
redis_store($secret, $answer['me']);
setcookie('indieauth', $secret, 0, "", "example.org");
header('Location: '.$home);
}
} else {
header('Location: '.$home.'/fail');
}
// example token storage in redis
function redis_store($secret, $me) {
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$secret = md5(rand());
$redis->hSet('indieauth:example.org', $secret, $me);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment