Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(oidc): record tabIds when service worker receives init event (release) #1423

Merged
Merged
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
7 changes: 6 additions & 1 deletion packages/oidc-client-service-worker/src/OidcServiceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const handleFetch = async (event: FetchEvent) => {
let newBody = actualBody;
for (let i = 0; i < numberDatabase; i++) {
const currentDb = currentDatabases[i];
const currentDbTabs = Object.keys(currentDb.state);
const currentDbTabs = currentDb.tabIds;

if (currentDb?.tokens != null) {
const claimsExtras = {
Expand Down Expand Up @@ -338,6 +338,7 @@ const handleMessage = async (event: ExtendableMessageEvent) => {
: trustedDomain.allowMultiTabLogin;
database[configurationName] = {
tokens: null,
tabIds: [],
state: {},
codeVerifier: {},
oidcServerConfiguration: null,
Expand Down Expand Up @@ -366,6 +367,7 @@ const handleMessage = async (event: ExtendableMessageEvent) => {
switch (data.type) {
case 'clear':
currentDatabase.tokens = null;
currentDatabase.tabIds = [];
currentDatabase.state = {};
currentDatabase.codeVerifier = {};
currentDatabase.demonstratingProofOfPossessionNonce = null;
Expand All @@ -391,6 +393,9 @@ const handleMessage = async (event: ExtendableMessageEvent) => {
}
currentDatabase.oidcServerConfiguration = oidcServerConfiguration;
currentDatabase.oidcConfiguration = data.data.oidcConfiguration;
if (!currentDatabase.tabIds.includes(tabId)) {
currentDatabase.tabIds.push(tabId);
}

if (currentDatabase.demonstratingProofOfPossessionConfiguration == null) {
const demonstratingProofOfPossessionConfiguration = getDpopConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const oidcConfigDefaults = {
demonstratingProofOfPossessionConfiguration: null,
configurationName: '',
tokens: null,
tabIds: [],
status: null,
state: {},
codeVerifier: {},
Expand Down
1 change: 1 addition & 0 deletions packages/oidc-client-service-worker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export type Nonce = {
export type OidcConfig = {
demonstratingProofOfPossessionConfiguration: DemonstratingProofOfPossessionConfiguration | null;
configurationName: string;
tabIds: string[];
tokens: Tokens | null;
status: Status;
state: Record<string, string | null>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('domains', () => {
default: {
configurationName: 'config',
tokens: {} as Tokens,
tabIds: [],
status: 'NOT_CONNECTED',
state: {},
codeVerifier: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class OidcConfigBuilder {
private oidcConfig: OidcConfig = {
configurationName: '',
tokens: null,
tabIds: [],
status: 'NOT_CONNECTED',
state: { tab1: '' },
codeVerifier: { tab1: '' },
Expand Down
Loading