Skip to content

Instantly share code, notes, and snippets.

@adamjmcgrath
Last active January 27, 2022 15:18
Show Gist options
  • Select an option

  • Save adamjmcgrath/4d3c7d4020db79a5b4dc5d2b81ffe1a2 to your computer and use it in GitHub Desktop.

Select an option

Save adamjmcgrath/4d3c7d4020db79a5b4dc5d2b81ffe1a2 to your computer and use it in GitHub Desktop.

Revisions

  1. adamjmcgrath renamed this gist Jan 27, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. adamjmcgrath created this gist Jan 27, 2022.
    38 changes: 38 additions & 0 deletions do web_message flow
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    (() => {
    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`
    );
    })();