Skip to content

Instantly share code, notes, and snippets.

@adamjmcgrath
Last active January 27, 2022 15:18
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 adamjmcgrath/4d3c7d4020db79a5b4dc5d2b81ffe1a2 to your computer and use it in GitHub Desktop.
Save adamjmcgrath/4d3c7d4020db79a5b4dc5d2b81ffe1a2 to your computer and use it in GitHub Desktop.
(() => {
const DOMAIN_URL = 'https://brucke.auth0.com';
const CLIENT_ID = 'wLSIP47wM39wKdDmOj6Zb5eSEw3JVhVp';
const iframe = window.document.createElement('iframe');
iframe.setAttribute('width', '0');
iframe.setAttribute('height', '0');
iframe.style.display = 'none';
window.addEventListener(
'message',
async e => {
if (e.origin !== DOMAIN_URL) return;
let response = e.data.response;
if (response.code) {
const tokens = await fetch(`${DOMAIN_URL}/oauth/token`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
client_id: CLIENT_ID,
code: response.code,
grant_type: 'authorization_code',
redirect_uri: window.location.origin
})
});
response = await tokens.json();
}
alert(JSON.stringify(response, null, 2));
},
false
);
window.document.body.appendChild(iframe);
iframe.setAttribute(
'src',
`${DOMAIN_URL}/authorize?client_id=${CLIENT_ID}&redirect_uri=${window.location.origin}&scope=openid%20profile%20email&response_type=code&response_mode=web_message&nonce=abc123&prompt=none`
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment