Created
May 13, 2010 19:09
-
-
Save davidrecordon/400268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't it be /.well-known/host-meta ?