Skip to content

Instantly share code, notes, and snippets.

@davidrecordon
Created May 13, 2010 19:09
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/400268 to your computer and use it in GitHub Desktop.
Save davidrecordon/400268 to your computer and use it in GitHub Desktop.
<?php
// fetches the JRDD 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 a the OpenID token endpoint URL or false.
function discover_openid_endpoint($curl, $scheme, $domain) {
$query = '?format=json';
// first try SSL
curl_setopt($curl, CURLOPT_URL,
'https://' . $domain . '/.well-known/host-meta' . $query);
$jrdd = curl_exec($curl);
// don't fallback to HTTP if the user explicitly said HTTPS
if (!$jrdd && $scheme != 'https') {
curl_setopt($curl, CURLOPT_URL,
'http://' . $domain . '/.well-known/host-meta' . $query);
$jrdd = curl_exec($curl);
}
// make sure we got something
if (!$jrdd) {
return false;
}
// make sure it has a links array
$jrdd = json_decode($jrdd, true);
if (!isset($jrdd['links'])) {
return false;
}
// find the openid href
foreach ($jrdd['link'] as $link) {
if ($link['rel'] == 'openid') {
return $link['href'];
}
}
return false;
}
@pfefferle
Copy link

Shouldn't it be /.well-known/host-meta ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment