Created
January 23, 2012 16:29
-
-
Save pfefferle/1664111 to your computer and use it in GitHub Desktop.
YQL Webfinger fix
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
<?xml version="1.0" encoding="UTF-8"?> | |
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd"> | |
<meta> | |
<sampleQuery>select * from {table} where account='pfefferle@notizblog.org'</sampleQuery> | |
</meta> | |
<bindings> | |
<select itemPath="" produces="XML"> | |
<urls> | |
<url>http://code.google.com/p/webfinger/</url> | |
</urls> | |
<inputs> | |
<key id='account' type='xs:string' paramType='variable' required='true'/> | |
</inputs> | |
<execute><![CDATA[ | |
// Remove the acct: if present | |
account = account.replace(/^acct:/, ""); | |
// Get the domain, later we can support more types | |
var split = account.split("@"); | |
if (split.length != 2) { | |
response.object = <error>must provide a valid account address</error>; | |
y.exit(); | |
} | |
var id = split[0]; | |
var domain = split[1]; | |
// Check for the host-meta | |
var hostmeta = y.rest("http://" + domain + "/.well-known/host-meta").accept("application/xrd+xml").contentType("application/xml").get(); | |
if (hostmeta.status != 200) { | |
response.object = <error>status: {hostmeta.status}</error>; | |
y.exit(); | |
} | |
hostmeta = hostmeta.response; | |
if (!(hostmeta.respo instanceof XML)) { | |
hostmeta = hostmeta.substring(hostmeta.indexOf("?>") + 2).replace("{", "<![CDATA[{]" + "]>"); | |
hostmeta = eval("var a__ = " + hostmeta + ";a__;"); | |
} | |
hostmeta = y.xmlToJson(hostmeta); | |
var host = hostmeta.XRD.Host; | |
if (!host) { | |
response.object = <error><message>Host not found</message><hostmeta>{hostmeta.response}</hostmeta></error>; | |
y.exit(); | |
} | |
/*if (host.content != domain) { | |
response.object = <error><message>Domain mismatch</message><hostmeta>{hostmeta.response}</hostmeta></error>; | |
y.exit(); | |
}*/ | |
var links = hostmeta.XRD.Link; | |
if (!(links instanceof Array)) { | |
var links = new Array(links); | |
} | |
for (var i in links) { | |
var link = links[i]; | |
var rel = link.rel; | |
if (rel.toLowerCase() == "lrdd") { | |
var url = link.template.replace("{%id}", encodeURI(account)); | |
url = url.replace("{%uri}", encodeURI("acct:" + account)); | |
url = url.replace("{id}", account); | |
url = url.replace("{uri}", "acct:" + account); | |
url = url.replace("{userInfo}", id); | |
url = url.replace("{%userInfo}", encodeURI(id)); | |
url = url.replace("{host}", domain); | |
url = url.replace("{%host}", encodeURI(domain)); | |
var webfinger = y.rest(url).accept("application/xrd+xml").contentType("application/xml").get(); | |
if (webfinger.status == 200) { | |
response.object = webfinger.response; | |
y.exit(); | |
} | |
} | |
} | |
response.object = <error><message>webfinger not found</message><account>{account}</account></error>; | |
y.exit(); | |
]]></execute> | |
</select> | |
</bindings> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment