Skip to content

Commit 6c2198e

Browse files
committed
Keep separate token caches for Simple and External browsers
1 parent 5ca74e3 commit 6c2198e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/api/getPortalUriWithToken.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import { Uri } from 'vscode';
33
import { extensionId, ServerSpec } from '../extension';
44
import { makeRESTRequest } from '../makeRESTRequest';
55

6-
const allTokens = new Map<string, string>();
6+
export enum BrowserTarget {
7+
SIMPLE = 0,
8+
EXTERNAL = 1
9+
}
10+
11+
const allTokens = [ new Map<string, string>(), new Map<string, string>()];
712

8-
export async function getPortalUriWithToken(name: string, scope?: vscode.ConfigurationScope): Promise<Uri | undefined> {
13+
export async function getPortalUriWithToken(target: BrowserTarget, name: string, scope?: vscode.ConfigurationScope): Promise<Uri | undefined> {
914

1015
const PORTAL_HOME = '/csp/sys/UtilHome.csp';
1116

@@ -16,19 +21,19 @@ export async function getPortalUriWithToken(name: string, scope?: vscode.Configu
1621
if (typeof spec !== 'undefined') {
1722

1823
// Retrieve previously cached token
19-
let token = allTokens.get(name) || '';
24+
let token = allTokens[target].get(name) || '';
2025

2126
// Revalidate and extend existing token, or obtain a new one
2227
const response = await makeRESTRequest("POST", spec, { apiVersion: 1, namespace: '%SYS', path:'/action/query' }, { query: 'select %Atelier_v1_Utils.General_GetCSPToken(?, ?) token', parameters: [PORTAL_HOME, token]});
2328

2429
if (!response) {
2530
// User will have to enter credentials
2631
token = '';
27-
allTokens.delete(name);
32+
allTokens[target].delete(name);
2833
}
2934
else {
3035
token = response.data?.result?.content[0]?.token || '';
31-
allTokens.set(name, token);
36+
allTokens[target].set(name, token);
3237
}
3338

3439
const webServer = spec.webServer;

src/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { importFromRegistry } from './commands/importFromRegistry';
1010
import { ServerManagerView, ServerTreeItem, SMTreeItem } from './ui/serverManagerView';
1111
import { addServer } from './api/addServer';
1212
import { getServerSummary } from './api/getServerSummary';
13-
import { getPortalUriWithToken } from './api/getPortalUriWithToken';
13+
import { BrowserTarget, getPortalUriWithToken } from './api/getPortalUriWithToken';
1414

1515
export interface ServerName {
1616
name: string,
@@ -78,7 +78,7 @@ export function activate(context: vscode.ExtensionContext) {
7878
context.subscriptions.push(
7979
vscode.commands.registerCommand(`${extensionId}.openPortalExternal`, (server?: ServerTreeItem) => {
8080
if (server?.contextValue?.match(/\.server\./) && server.name) {
81-
getPortalUriWithToken(server.name).then((uriWithToken) => {
81+
getPortalUriWithToken(BrowserTarget.EXTERNAL, server.name).then((uriWithToken) => {
8282
if (uriWithToken) {
8383
vscode.env.openExternal(uriWithToken);
8484
}
@@ -89,7 +89,7 @@ export function activate(context: vscode.ExtensionContext) {
8989
context.subscriptions.push(
9090
vscode.commands.registerCommand(`${extensionId}.openPortalTab`, (server?: ServerTreeItem) => {
9191
if (server?.contextValue?.match(/\.server\./) && server.name) {
92-
getPortalUriWithToken(server.name).then((uriWithToken) => {
92+
getPortalUriWithToken(BrowserTarget.SIMPLE, server.name).then((uriWithToken) => {
9393
if (uriWithToken) {
9494
//
9595
// It is essential to pass skipEncoding=true when converting the uri to a string,

0 commit comments

Comments
 (0)