Skip to content

Instantly share code, notes, and snippets.

@davidrecordon
Created May 12, 2010 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidrecordon/398264 to your computer and use it in GitHub Desktop.
Save davidrecordon/398264 to your computer and use it in GitHub Desktop.
<?php
// fetches the host-meta.json file for the given domain/identifier. $scheme
// is the scheme from user input, $domain is the domain, and $identifier is
// the normalized user input. Returns an associative array containing the
// data from host-meta.json or false.
function fetch_host_meta($curl, $scheme, $domain, $identifier) {
$query = '?uri=' . urlencode($identifier);
// first try SSL
curl_setopt($curl, CURLOPT_URL,
'https://' . $domain . '/.well-known/host-meta.json' . $query);
$host_meta = curl_exec($curl);
// don't fallback to HTTP if the user explicitly said HTTPS
if (!$host_meta && $scheme != 'https') {
curl_setopt($curl, CURLOPT_URL,
'http://' . $domain . '/.well-known/host-meta.json' . $query);
$host_meta = curl_exec($curl);
}
// make sure we got something
if (!$host_meta) {
return false;
}
$host_meta = json_decode($host_meta, true);
if (!isset($host_meta['openid']['token_endpoint'])) {
return false;
} else {
return $host_meta;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment