Permalink
Browse files

Creates support for google's IdP discovery as described in https://si…

  • Loading branch information...
1 parent 9e8dff7 commit 4f36a212e95837e00c66783f95cd34370b65ea92 @snoble snoble committed Jan 13, 2012
Showing with 44 additions and 1 deletion.
  1. +44 −1 openid.js
View
@@ -428,6 +428,20 @@ var _parseHtml = function(htmlUrl, html, callback, hops)
}
}
+var _parseHostMeta = function(hostMeta, callback)
+{
+ var match = /^Link: <([^\n\r]+)>;/.exec(hostMeta);
+ if(match != null)
+ {
+ var xriUrl = match[0].slice(7,match.length - 4);
@cprecioso

cprecioso Dec 8, 2015

Shouldn't this be var xriUrl = match[0].slice(7,match[0].length - 4);?

@snoble

snoble Dec 8, 2015

Contributor

I'm not sure... this code was written a long time ago (not sure it still merges)

@cprecioso

cprecioso Dec 8, 2015

But it doesn't really make any sense to compare this with the length of the matches array instead of the length of the match string.

Also, slice accepts negative numbers, so var xriUrl = match[0].slice(7,-4); would do away with this problem altogether.

+ _resolveXri(xriUrl, callback);
+ }
+ else
+ {
+ callback(null)
+ }
+}
+
var _resolveXri = function(xriUrl, callback, hops)
{
if(!hops)
@@ -510,6 +524,28 @@ var _resolveHtml = function(identifier, callback, hops, data)
}
+var _resolveHostMeta = function(identifier, callback, fallBackToProxy)
+{
+ var host = url.parse(identifier);
+ hostMetaUrl = fallBackToProxy ? 'https://www.google.com/accounts/o8/.well-known/host-meta?hd=' + host.host : host.protocol + '://' + host.host + '/.well-known/host-meta';
+ _get(hostMetaUrl, null, function(data, headers, statusCode)
+ {
+ if(statusCode != 200 || data == null)
+ {
+ if(!fallBackToProxy){
+ _resolveHostMeta(identifier, callback, true);
+ }
+ else{
+ callback(null);
+ }
+ }
+ else
+ {
+ _parseHostMeta(data, callback);
+ }
+ });
+}
+
openid.discover = function(identifier, callback)
{
identifier = _normalizeIdentifier(identifier);
@@ -531,7 +567,14 @@ openid.discover = function(identifier, callback)
// Fallback to HTML discovery
_resolveHtml(identifier, function(providers)
{
- callback(null, providers);
+ if(providers == null || providers.length == 0){
+ _resolveHostMeta(identifier, function(providers){
+ callback(null, providers);
+ });
+ }
+ else{
+ callback(null, providers);
+ }
});
}
else

0 comments on commit 4f36a21

Please sign in to comment.