Skip to content

Commit

Permalink
feat(OIDC): get clientId from server (#16378)
Browse files Browse the repository at this point in the history
* feat(OIDC): get clientId from server

* chore: remove types file

* chore: optional secret
  • Loading branch information
aweiss-dev authored Dec 14, 2023
1 parent 92df99a commit f7508c7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 53 deletions.
7 changes: 4 additions & 3 deletions src/script/E2EIdentity/OIDCService/OIDCService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import {UserManager, User, UserManagerSettings} from 'oidc-client-ts';

import {clearKeysStartingWith} from 'Util/localStorage';

import {OidcClientData} from './OIDCService.types';

interface OIDCServiceConfig {
authorityUrl: string;
redirectUri: string;
oidcClient: OidcClientData;
oidcClient: {
id: string;
secret?: string;
};
}

export class OIDCService {
Expand Down
23 changes: 0 additions & 23 deletions src/script/E2EIdentity/OIDCService/OIDCService.types.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/script/E2EIdentity/OIDCService/OIDCServiceStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,22 @@
*
*/

import {OidcClientData} from './OIDCService.types';

const TargetURLKey = 'E2EIdentity_OIDCService_TargetURL';
const clientDataKey = 'E2EIdentity_OIDCService_ClientData';

const OIDCServiceStore = {
store: {
clientData: (data: OidcClientData) => localStorage.setItem(clientDataKey, JSON.stringify(data)),
targetURL: (url: string) => localStorage.setItem(TargetURLKey, url),
},
get: {
clientData: (): OidcClientData => {
// MOCK: store targetURL and clientData in OIDCServiceStore
// TODO: remove this once we have a proper OIDC service
return {
id: 'wireapp',
secret: 'dUpVSGx2dVdFdGQ0dmsxWGhDalQ0SldU',
};
/*
const clientData = localStorage.getItem(clientDataKey);
if (!clientData) {
throw new Error('No client data found in OIDCServiceStore');
}
return JSON.parse(clientData);
*/
},
targetURL: () => localStorage.getItem(TargetURLKey),
},
has: {
clientData: () => localStorage.getItem(clientDataKey) !== null,
targetURL: () => localStorage.getItem(TargetURLKey) !== null,
},
clear: {
clientData: () => localStorage.removeItem(clientDataKey),
targetURL: () => localStorage.removeItem(TargetURLKey),
all: () => {
OIDCServiceStore.clear.targetURL();
OIDCServiceStore.clear.clientData();
},
},
};
Expand Down
17 changes: 12 additions & 5 deletions src/script/E2EIdentity/OIDCService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,27 @@ import {OIDCServiceStore} from './OIDCServiceStorage';
// lots of hardcoded values here, but this is just for testing until we have a proper OIDC service
export const getOIDCServiceInstance = (): OIDCService => {
const targetURL = OIDCServiceStore.get.targetURL();
const clientData = OIDCServiceStore.get.clientData();

// if there is no targetURL, we cannot create an OIDCService
if (!targetURL) {
throw new Error('No target URL found in OIDCServiceStore');
}

const idpUrl = new URL(targetURL);
const idpClientId = idpUrl.searchParams.get('clientId');

// if there is no clientData ID, we cannot create an OIDCService
if (!clientData || !clientData.id) {
throw new Error('No client data found in OIDCServiceStore');
if (!idpClientId) {
throw new Error('No clientId provided by the targetUrl');
}

const oidcService = new OIDCService({
oidcClient: clientData,
authorityUrl: targetURL,
oidcClient: {
id: idpClientId,
// this is a secret that is only used for testing and needs to be removed by backend
secret: 'dUpVSGx2dVdFdGQ0dmsxWGhDalQ0SldU',
},
authorityUrl: idpUrl.origin + idpUrl.pathname,
redirectUri: `${location.origin}/oidc`,
});
return oidcService;
Expand Down

0 comments on commit f7508c7

Please sign in to comment.