Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 5413cc8b9d
Fetching contributors…
Cannot retrieve contributors at this time
87 lines (73 sloc) 3.21 KB
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="" https="true">
<author>Erik Eldridge</author>
Discovers an openid provider's log-in uri using the normalized openid passed in
<sampleQuery>select * from {table} where normalizedId=""</sampleQuery>
<select produces="XML">
<key id="normalizedId" type="xs:string" paramType="variable" required="true"/>
y.include( 'store://pitrYOXYb8vQfiui4rUYPX' );
if(!String.prototype.supplant){String.prototype.supplant=function(o){return this.replace(/{([^{}]*)}/g,function(a,b){var r=o[b];return typeof r==='string'||typeof r==='number'?r:a;});};}if(!String.prototype.trim){String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"");};}
//use a wrapper fn so we can exit early, ie as a workaround for lack of exit(), die(), etc
response.object = function() {
//try yadis
var yadisTableUri = 'store://EyZjOZK9SHXU3IGArp7K58';
var yadisQuery = 'use "{tableUri}" as yadis; select * from yadis where uri = "{normalizedId}"'.supplant({
'tableUri' : yadisTableUri,
'normalizedId' : normalizedId
var yadisResults = y.xmlToJson( y.query( yadisQuery ).results );
//results.result only shows up for success responses. not sure why
if ( yadisResults.results.result && 'success' === yadisResults.results.result.status ) {
var xrdsQuery = 'select * from xml where url="{url}"'.supplant({
'url' : yadisResults.results.result.uri
var xrdsResult = y.xmlToJson( y.query( xrdsQuery ).results );
//kludge: for the xrds doc, xmlToJson creates a 'content' node
if ( xrdsResult.results.XRDS.XRD.Service.URI.content ) {
var xrdsUri = xrdsResult.results.XRDS.XRD.Service.URI.content;
} else {
var xrdsUri = xrdsResult.results.XRDS.XRD.Service.URI;
return {
'success' : xrdsUri
//try scraping w/ the native html table
var htmlQuery = 'select * from html where url="{url}" and xpath=\'//link[@rel="openid2.provider"]\''.supplant({
'url' : normalizedId
var htmlResults = y.xmlToJson( y.query( htmlQuery ).results );
if ( htmlResults.results ) {
return {
'success' :
//try raw html fetch
var htmlResults = normalizedId ).get().response;
//this is super brittle, but it works for flickr, so it's a start
var matches = htmlResults.match(/<link rel="openid2\.provider" href="([^"]+)"[^>]*>/);
if ( matches[1] ) {
return {
'success' : matches[1]
//ok, yadis and html fail, so give up
return {
'error': 'yadis and html fail'
} ();
Jump to Line
Something went wrong with that request. Please try again.