Skip to content

Commit ea524a6

Browse files
committed
simp
1 parent c6ac3a5 commit ea524a6

3 files changed

Lines changed: 16 additions & 20 deletions

File tree

src/api/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ export class AtelierAPI {
6767
const superserverPort = this.externalServer
6868
? this._config.superserverPort
6969
: workspaceState.get(wsKey + ":superserverPort", this._config.superserverPort);
70-
const accessToken = workspaceState.get(wsKey + ":password", undefined);
71-
if (accessToken !== undefined) {
72-
auth.resolve({ accessToken });
73-
}
70+
auth.resolve({ accessToken: workspaceState.get(wsKey + ":password", undefined) });
7471
const apiVersion = workspaceState.get(wsKey + ":apiVersion", DEFAULT_API_VERSION);
7572
const serverVersion = workspaceState.get(wsKey + ":serverVersion", DEFAULT_SERVER_VERSION);
7673
const docker = workspaceState.get(wsKey + ":docker", false);
@@ -365,6 +362,10 @@ export class AtelierAPI {
365362
let auth: Promise<any>;
366363
let authRequest = authRequestMap.get(mapKey);
367364
if (cookies.length || (method === "HEAD" && !originalPath)) {
365+
// Only send basic authorization if username and password specified (including blank, for unauthenticated access)
366+
if (this.config.auth.resolved()) {
367+
headers["Authorization"] = this.config.auth.httpAuthorizationHeader;
368+
}
368369
auth = Promise.resolve(cookies);
369370
} else if (!cookies.length) {
370371
if (!authRequest) {
@@ -374,10 +375,6 @@ export class AtelierAPI {
374375
}
375376
auth = authRequest;
376377
}
377-
// Always set Authorization header if credentials are resolved
378-
if (this.config.auth.resolved()) {
379-
headers["Authorization"] = this.config.auth.httpAuthorizationHeader;
380-
}
381378

382379
const outputTraffic = vscode.workspace.getConfiguration("objectscript").get<boolean>("outputRESTTraffic");
383380
let cookie;

src/commands/serverActions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type ServerAction = { detail: string; id: string; label: string; rawLink?: strin
2525
export async function serverActions(): Promise<void> {
2626
const { apiTarget, configName: workspaceFolder } = connectionTarget();
2727
const api = new AtelierAPI(apiTarget);
28-
const { active, host = "", ns = "", https, port = 0, pathPrefix, auth: authorization, docker } = api.config;
28+
const { active, host = "", ns = "", https, port = 0, pathPrefix, auth, docker } = api.config;
2929
const explorerCount = (await explorerProvider.getChildren()).length;
3030
if (!explorerCount && (!docker || host === "")) {
3131
await vscode.commands.executeCommand("ObjectScriptExplorer.focus");
@@ -152,7 +152,7 @@ export async function serverActions(): Promise<void> {
152152
.replace("${serverAuth}", "")
153153
.replace("${ns}", nsEncoded)
154154
.replace("${namespace}", ns == "%SYS" ? "sys" : nsEncoded.toLowerCase())
155-
.replace("${username}", authorization.username)
155+
.replace("${username}", auth.username)
156156
.replace("${classname}", classname)
157157
.replace("${classnameEncoded}", classnameEncoded)
158158
.replace("${project}", project);
@@ -248,7 +248,7 @@ export async function serverActions(): Promise<void> {
248248
if (addin) {
249249
sendStudioAddinTelemetryEvent(addin.label);
250250
let params = `Namespace=${nsEncoded}`;
251-
params += `&User=${encodeURIComponent(authorization.username)}`;
251+
params += `&User=${encodeURIComponent(auth.username)}`;
252252
if (project != "") {
253253
params += `&Project=${encodeURIComponent(project)}`;
254254
}

src/extension.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export let checkingConnection = false;
208208
export let serverManagerApi: serverManager.ServerManagerAPI;
209209

210210
/** Map of the intersystems.server connection specs we have resolved via the API to that extension */
211-
const resolvedConnSpecs = new Map<string, serverManager.IServerSpec & { accessToken?: string }>();
211+
const resolvedConnSpecs = new Map<string, serverManager.IServerSpec>();
212212

213213
/**
214214
* If servermanager extension is available, fetch the connection spec unless already cached.
@@ -267,10 +267,10 @@ export async function resolveConnectionSpec(
267267
}
268268

269269
async function resolvePassword(
270-
serverSpec: Pick<serverManager.IServerSpec, "name" | "auth">,
270+
serverSpec: serverManager.IServerSpec,
271271
ignoreUnauthenticated = false
272272
): Promise<string | undefined> {
273-
if (!((serverSpec.auth.resolved() as boolean) || ignoreUnauthenticated)) {
273+
if (!(serverSpec.auth.resolved() as boolean) || ignoreUnauthenticated) {
274274
const scopes = [serverSpec.name, serverSpec.auth?.username || ""];
275275

276276
// Handle Server Manager extension version < 3.8.0
@@ -304,15 +304,14 @@ export async function resolveUsernameAndPassword(
304304
): Promise<(serverManager.IServerSpec & { accessToken?: string }) | undefined> {
305305
const { auth: _auth, ...newSpec } = oldSpec;
306306
newSpec.name = serverName;
307-
const auth = _auth.clone();
307+
const auth = _auth?.clone();
308308

309309
const accessToken = await resolvePassword({ ...newSpec, auth }, true);
310-
if (auth.resolved()) {
310+
if (auth.resolve({ accessToken })) {
311311
// Update the connection spec
312312
resolvedConnSpecs.set(serverName, {
313313
...oldSpec,
314314
auth,
315-
accessToken,
316315
});
317316
return resolvedConnSpecs.get(serverName);
318317
}
@@ -365,7 +364,7 @@ export async function checkConnection(
365364
_onDidChangeConnection.fire();
366365
}
367366
let api = new AtelierAPI(apiTarget, false);
368-
const { active, host = "", port = 0, superserverPort = 0, ns = "", auth: authorization } = api.config;
367+
const { active, host = "", port = 0, superserverPort = 0, ns = "", auth } = api.config;
369368
vscode.commands.executeCommand("setContext", "vscode-objectscript.connectActive", active);
370369
if (!panel.text) {
371370
panel.text = `${PANEL_LABEL}`;
@@ -451,10 +450,10 @@ export async function checkConnection(
451450
const { serverName, host, port, pathPrefix } = api.config;
452451
if (serverName) {
453452
panel.tooltip = new vscode.MarkdownString(
454-
`Connected to \`${host}:${port}${pathPrefix}\` as \`${authorization.username}\``
453+
`Connected to \`${host}:${port}${pathPrefix}\` as \`${auth.username}\``
455454
);
456455
} else {
457-
panel.tooltip = new vscode.MarkdownString(`Connected as \`${authorization.username}\``);
456+
panel.tooltip = new vscode.MarkdownString(`Connected as \`${auth.username}\``);
458457
}
459458
inactiveServerIds.delete(api.serverId);
460459
if (!api.externalServer) await setConnectionState(configName, true);

0 commit comments

Comments
 (0)