Created
June 30, 2015 09:56
-
-
Save cianclarke/8de794a7e30ecc84c939 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
var fh = fh || {}; | |
fh.oauth = function(url, cb){ | |
var browser = window.open(url, '_blank', 'location=yes'); | |
browser.addEventListener('loadstop', function(e){ | |
if (e.url.indexOf('/authed')>-1){ | |
browser.executeScript({ | |
code: "JSON.parse(document.body.querySelector('pre').textContent)" | |
}, function(result) { | |
// Result will be required oAuth creds | |
browser.close(); | |
if (!result || result.length === 0 || !result[0].passport || !result[0].passport.user){ | |
return cb('Could not find authentication token details on response'); | |
} | |
return cb(null, result[0].passport.user) | |
}); | |
} | |
if (e.url.indexOf('/error')>-1){ | |
browser.close(); | |
return cb('Error authenticating you over oAuth') | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment