Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,25 @@ export const callApi = async ({ auth0, url, btnId }) => {

history.pushState('', null, window.location.pathname);

const accessToken = ['scoped-api-btn', 'private-api-btn'].includes(btnId)
? await auth0.refreshTokens(true)
: await auth0.getAccessToken();
let accessToken = undefined;

if (['step-up-api-btn'].includes(btnId)) {
const authOptions = {
cacheMode: "off",
authorizationParams: {
acr_values: `http://schemas.openid.net/pape/policies/2007/06/multi-factor`,
scope: "authRocks:admin",
redirect_uri: window.location.href,
audience: auth0.config?.audience,
},
}
accessToken = await auth0.getTokenWithPopup(authOptions);
}
else {
accessToken = ['scoped-api-btn', 'private-api-btn'].includes(btnId)
? await auth0.refreshTokens(true)
: await auth0.getAccessToken();
}

const fetchOptions = {
method: 'GET',
Expand Down Expand Up @@ -96,6 +112,7 @@ export default async () => {
const publicAPIButton = document.querySelector('#public-api-btn');
const privateAPIButton = document.querySelector('#private-api-btn');
const scopedAPIButton = document.querySelector('#scoped-api-btn');
const stepUpAPIButton = document.querySelector("#step-up-api-btn");

loginButton.addEventListener('click', () => auth0.login());

Expand Down Expand Up @@ -127,6 +144,14 @@ export default async () => {
})
);

stepUpAPIButton.addEventListener('click', () =>
callApi({
auth0,
url: window.location.origin + apiUrl + '/admin',
btnId: 'step-up-api-btn',
})
);

// If unable to parse the history hash, default to the root URL
if (!showContentFromUrl(window.location.pathname)) {
showContentFromUrl('/');
Expand Down
Loading