[PM-11461] Fix jit proivisioning for snap desktop (#10794)

* Fix snap jit privisioning

* Fix server keeping connection open on favicon request
This commit is contained in:
Bernd Schoolmann 2024-09-06 00:15:09 +02:00 committed by GitHub
parent 3f25b9bbfc
commit b2966b158a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 13 deletions

View File

@ -18,10 +18,10 @@ export class SSOLocalhostCallbackService {
private messagingService: MessageSender, private messagingService: MessageSender,
) { ) {
ipcMain.handle("openSsoPrompt", async (event, { codeChallenge, state }) => { ipcMain.handle("openSsoPrompt", async (event, { codeChallenge, state }) => {
const { ssoCode } = await this.openSsoPrompt(codeChallenge, state); const { ssoCode, recvState } = await this.openSsoPrompt(codeChallenge, state);
this.messagingService.send("ssoCallback", { this.messagingService.send("ssoCallback", {
code: ssoCode, code: ssoCode,
state: state, state: recvState,
redirectUri: this.ssoRedirectUri, redirectUri: this.ssoRedirectUri,
}); });
}); });
@ -30,24 +30,20 @@ export class SSOLocalhostCallbackService {
private async openSsoPrompt( private async openSsoPrompt(
codeChallenge: string, codeChallenge: string,
state: string, state: string,
): Promise<{ ssoCode: string; orgIdentifier: string }> { ): Promise<{ ssoCode: string; recvState: string }> {
const env = await firstValueFrom(this.environmentService.environment$); const env = await firstValueFrom(this.environmentService.environment$);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const callbackServer = http.createServer((req, res) => { const callbackServer = http.createServer((req, res) => {
// after 5 minutes, close the server
setTimeout(
() => {
callbackServer.close(() => reject());
},
5 * 60 * 1000,
);
const urlString = "http://localhost" + req.url; const urlString = "http://localhost" + req.url;
const url = new URL(urlString); const url = new URL(urlString);
const code = url.searchParams.get("code"); const code = url.searchParams.get("code");
if (code == null) {
res.writeHead(404);
res.end("not found");
return;
}
const receivedState = url.searchParams.get("state"); const receivedState = url.searchParams.get("state");
const orgIdentifier = this.getOrgIdentifierFromState(receivedState);
res.setHeader("Content-Type", "text/html"); res.setHeader("Content-Type", "text/html");
if (code != null && receivedState != null && this.checkState(receivedState, state)) { if (code != null && receivedState != null && this.checkState(receivedState, state)) {
res.writeHead(200); res.writeHead(200);
@ -60,7 +56,7 @@ export class SSOLocalhostCallbackService {
callbackServer.close(() => callbackServer.close(() =>
resolve({ resolve({
ssoCode: code, ssoCode: code,
orgIdentifier: orgIdentifier, recvState: receivedState,
}), }),
); );
} else { } else {
@ -74,6 +70,7 @@ export class SSOLocalhostCallbackService {
callbackServer.close(() => reject()); callbackServer.close(() => reject());
} }
}); });
let foundPort = false; let foundPort = false;
const webUrl = env.getWebVaultUrl(); const webUrl = env.getWebVaultUrl();
for (let port = 8065; port <= 8070; port++) { for (let port = 8065; port <= 8070; port++) {
@ -102,6 +99,14 @@ export class SSOLocalhostCallbackService {
if (!foundPort) { if (!foundPort) {
reject(); reject();
} }
// after 5 minutes, close the server
setTimeout(
() => {
callbackServer.close(() => reject());
},
5 * 60 * 1000,
);
}); });
} }