Skip to content

Commit

Permalink
Impersonation capabilities disabled by default, rename to
Browse files Browse the repository at this point in the history
imperativeImpersonation
  • Loading branch information
garronej committed Oct 20, 2024
1 parent b5ef77c commit 69b8542
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/mock/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export async function createMockOidc<
}
: {
"authMethod": "silent signin"
})
}),
"isImperativeImpersonation": false
});
}
27 changes: 21 additions & 6 deletions src/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export declare namespace Oidc {
subscribeToAutoLogoutCountdown: (
tickCallback: (params: { secondsLeft: number | undefined }) => void
) => { unsubscribeFromAutoLogoutCountdown: () => void };
isImperativeImpersonation: boolean;
} & (
| {
/**
Expand Down Expand Up @@ -200,6 +201,8 @@ export type ParamsOfCreateOidc<
autoLogoutParams?: Parameters<Oidc.LoggedIn<any>["logout"]>[0];
isAuthGloballyRequired?: IsAuthGloballyRequired;
doEnableDebugLogs?: boolean;

doAllowImperativeImpersonation?: boolean;
};

const prOidcByConfigHash = new Map<string, Promise<Oidc<any>>>();
Expand Down Expand Up @@ -315,7 +318,8 @@ export async function createOidc_nonMemoized<
__unsafe_ssoSessionIdleSeconds,
autoLogoutParams = { "redirectTo": "current page" },
isAuthGloballyRequired = false,
postLoginRedirectUrl
postLoginRedirectUrl,
doAllowImperativeImpersonation = false
} = params;

const { issuerUri, clientId, scopes, configHash, log } = preProcessedParams;
Expand Down Expand Up @@ -407,7 +411,15 @@ export async function createOidc_nonMemoized<
await new Promise<never>(() => {});
}

maybeImpersonate({ configHash });
const isImperativeImpersonation = (() => {
if (!doAllowImperativeImpersonation) {
return false;
}

const { isImperativeImpersonation } = maybeImpersonate({ configHash });

return isImperativeImpersonation;
})();

const oidcClientTsUserManager = new OidcClientTsUserManager({
configHash,
Expand Down Expand Up @@ -1517,7 +1529,8 @@ export async function createOidc_nonMemoized<
})
: {
"authMethod": resultOfLoginProcess.authMethod
})
}),
isImperativeImpersonation
});

{
Expand Down Expand Up @@ -1761,7 +1774,7 @@ function oidcClientTsUserToTokens<DecodedIdToken extends Record<string, unknown>
return tokens;
}

function maybeImpersonate(params: { configHash: string }) {
function maybeImpersonate(params: { configHash: string }): { isImperativeImpersonation: boolean } {
const { configHash } = params;

const value = (() => {
Expand Down Expand Up @@ -1795,7 +1808,7 @@ function maybeImpersonate(params: { configHash: string }) {
})();

if (value === undefined) {
return;
return { "isImperativeImpersonation": false };
}

const arr = JSON.parse(decodeBase64(value)) as {
Expand Down Expand Up @@ -1845,6 +1858,8 @@ function maybeImpersonate(params: { configHash: string }) {
})
);

break;
return { "isImperativeImpersonation": true };
}

return { "isImperativeImpersonation": false };
}

0 comments on commit 69b8542

Please sign in to comment.