Skip to content

Instantly share code, notes, and snippets.

@clayrisser
Created March 12, 2018 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clayrisser/b218c18249d8c0324fca2919cff2a119 to your computer and use it in GitHub Desktop.
Save clayrisser/b218c18249d8c0324fca2919cff2a119 to your computer and use it in GitHub Desktop.
Social Login Example
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Document</title>
</head>
<body>
<a onclick="loginGithub()" href="#">Login w/ GitHub</a>
</body>
<script>
function loginGithub() {
var githubPage = window.open('http://localhost:6600/api/v1/auth/provider/github');
function githubPageClosed() {
if (githubPage.closed) {
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "http://localhost:6600/api/v1/auth/authed");
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Postman-Token", "16c4e463-e2c8-3816-2c6a-5daf55ac2a1a");
xhr.send(data);
clearInterval(timer);
}
}
var timer = setInterval(githubPageClosed, 500);
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment