-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
389 additions
and
83 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class AuthenticationError extends Error { | ||
constructor({error, description}) { | ||
super(description || error); | ||
this.error = error; | ||
this.description = description; | ||
} | ||
} | ||
module.exports = AuthenticationError; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class IFrameError extends Error {} | ||
module.exports = IFrameError; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Sample App</title> | ||
<link rel='stylesheet' href='index.css'/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"/> | ||
</head> | ||
<body> | ||
<div class="main-container"> | ||
<div class="logo"> | ||
<img class="logo-icon" src="images/app_id_icon.svg"> | ||
</div> | ||
<div class="text-div" id="header"> | ||
Welcome to your<br/>App ID SPA sample | ||
</div> | ||
<div class="text-div" id="welcome"> | ||
</div> | ||
<div class="flex-bottom" id="error"></div> | ||
<div id="login-button-div" class="flex-top"> | ||
<button id="login" class="button">Login</button> | ||
</div> | ||
<div class="bottom-container"> | ||
<div class="flex-bottom" id="id_token"></div> | ||
<div class="flex-bottom" id="user_info"></div> | ||
</div> | ||
</div> | ||
</div> | ||
<script type='text/javascript' src="appid.js"></script> | ||
<script src="https://cdn.auth0.com/js/auth0-spa-js/1.0/auth0-spa-js.production.js"></script> | ||
<script> | ||
(async function () { | ||
const auth0 = await createAuth0Client({ | ||
domain: 'customsamlappid.auth0.com', | ||
client_id: 'dWyjoqtt6eh_fGLmv6VDTpolILYD3GDb' | ||
}); | ||
try { | ||
const token = await auth0.getTokenSilently(); | ||
document.getElementById('id_token').textContent = JSON.stringify(token); | ||
// await appID.init({ | ||
// clientId: '1b0e3658-fc1f-402e-843c-18402d4dbe58', | ||
// discoveryEndpoint: 'http://7cd6e215.ngrok.io/oauth/v4/5b1eb5f1-34bd-41fd-b6dd-e257c188a4dd/.well-known/openid-configuration' | ||
// }); | ||
} catch (e) { | ||
document.getElementById('error').textContent = 'failed'; | ||
} | ||
// try { | ||
// const tokens = await appID.silentSignin(); | ||
// if (tokens) { | ||
// document.getElementById('id_token').textContent = JSON.stringify(tokens.idTokenPayload); | ||
// } else { | ||
// document.getElementById('login').setAttribute('class', 'button'); | ||
// } | ||
// } catch (e) { | ||
// document.getElementById('error').textContent = e; | ||
// document.getElementById('login').setAttribute('class', 'button'); | ||
// } | ||
document.getElementById('login').addEventListener('click', async () => { | ||
document.getElementById('error').textContent = ''; | ||
document.getElementById('login').setAttribute('class', 'hidden'); | ||
let signin = await auth0.loginWithPopup(); | ||
//logged in. you can get the user profile like this: | ||
const user = await auth0.getUser(); | ||
console.log(user); | ||
// try { | ||
// const tokens = await appID.signinWithPopup(); | ||
// let userInfo = await appID.getUserInfo(tokens.accessToken); | ||
// document.getElementById("login").style.display = 'none'; | ||
// let decodeIDToken = tokens.idTokenPayload; | ||
// document.getElementById('welcome').innerHTML = 'Hello, ' + decodeIDToken.name; | ||
// document.getElementById('id_token').textContent = JSON.stringify(decodeIDToken); | ||
document.getElementById('user_info').textContent = JSON.stringify(user); | ||
// } catch (e) { | ||
// document.getElementById('error').textContent = e; | ||
// } | ||
|
||
}); | ||
})() | ||
</script> | ||
</body> | ||
</html> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const IFrameError = require('../errors/IFrameError'); | ||
|
||
class IFrameController { | ||
constructor({w = window} = {}) { | ||
this.window = w; | ||
}; | ||
|
||
open(url) { | ||
this.iFrame = this.window.document.createElement('iframe'); | ||
this.iFrame.src = url; | ||
this.iFrame.width = 0; | ||
this.iFrame.height = 0; | ||
this.window.document.body.appendChild(this.iFrame); | ||
} | ||
|
||
remove() { | ||
window.document.body.removeChild(this.iFrame); | ||
} | ||
|
||
async waitForMessage({messageType}) { | ||
return new Promise((resolve, reject) => { | ||
const timer = setInterval(() => { | ||
reject(new IFrameError('Silent sign-in timed out')); | ||
}, 5 * 1000); | ||
window.addEventListener('message', message => { | ||
clearInterval(timer); | ||
if (!message.data || message.data.type !== messageType) { | ||
return; | ||
} | ||
|
||
resolve(message); | ||
}); | ||
}); | ||
} | ||
} | ||
module.exports = IFrameController; |
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
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
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
Oops, something went wrong.