Skip to content

Instantly share code, notes, and snippets.

View davidrecordon's full-sized avatar

David Recordon davidrecordon

View GitHub Profile
#!/usr/bin/php
<?php
$secret = 'n39niewh32iblk0';
$request = array(
'issuer' => 'mySuperClientID',
'key_id' => 'not sure if this is needed for OAuth since we have the client id',
'alg' => 'HMAC-SHA256',
'not_before' => time(),
'token_lifetime' => 60000,
'audience' => 'http://resource.example.com/foo',
<?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);
<?php
$host_meta = fetch_host_meta($curl, $parsed['scheme'], $parsed['domain'], $identifier);
if (isset($host_meta['lrdd']['priority'])) {
$priority = $host_meta['lrdd']['priority'];
} else {
$priority = 'host';
}
$link_href = false;
<?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,
<?php
// $input is a string. return value is a hash.
function parse_input($input) {
$url = @parse_url($input);
if (!$url) {
die("That isn't a valid identifier!\n");
}
if (isset($url['user']) || isset($url['pass'])) {
die("We don't support username:password syntax.\n");
}
<?php
// turn what we figured out the user entered into a canonicalized string.
// $parsed is a hash with keys of scheme, user, domain, port, and path.
function normalize_input($parsed) {
$identifier = '';
if ($parsed['scheme'] == 'acct') {
$identifier = 'acct:' . $parsed['user'] . '@' . $parsed['domain'];
} else {
$identifier = $parsed['scheme'] . '://' . $parsed['domain'];
if ($parsed['port']) {
<?php
error_reporting(E_ALL|E_STRICT);
$input = "david@davidrecordon.com";
$input = "https://davidrecordon.com";
$input = "www.davidrecordon.com";
$parsed = parse_input($input);
$after = normalize_input($parsed);
echo $input . ' -> ' . $after . "\n";
<?php
// you need an access token, and it might require the user_likes permission.
// see http://developers.facebook.com/docs/authentication. Just trying this
// out for yourself, grab one of your access tokens from
// http://developers.facebook.com/docs/api.
$access_token = '';
$user = '';
$api = 'https://graph.facebook.com/';
$data = file_get_contents($api . $user . '/likes?access_token=' . $access_token);