Skip to content

Commit

Permalink
Prompt for password if the stored one didn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
gjsjohnmurray committed Oct 8, 2024
1 parent 92604b3 commit 797655f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/authenticationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export class ServerManagerAuthenticationProvider implements AuthenticationProvid
}

if (sessions.length === 1) {
sessions = sessions.filter(async (session) => await this._isStillValid(session));
if (!(await this._isStillValid(sessions[0]))) {
sessions = [];
}
}
return sessions || [];
}
Expand Down Expand Up @@ -214,8 +216,8 @@ export class ServerManagerAuthenticationProvider implements AuthenticationProvid
serverSpec.username = session.userName;
serverSpec.password = session.accessToken;
const response = await makeRESTRequest("HEAD", serverSpec);
if (response?.status !== 200) {
this._removeSession(session.id, true);
if (response?.status === 401) {
await this._removeSession(session.id, true);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/makeRESTRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export async function makeRESTRequest(
return respdata;
} catch (error) {
console.log(error);
return undefined;
return error.response;
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/ui/serverManagerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,13 @@ async function serverFeatures(element: ServerTreeItem, params?: any): Promise<Fe
return undefined;
}

const response = await makeRESTRequest("HEAD", serverSpec);
if (!response || response.status !== 200) {
let response = await makeRESTRequest("HEAD", serverSpec);
if (response?.status === 401) {
// Authentication error, so retry in case first attempt cleared a no-longer-valid stored password
serverSpec.password = undefined;
response = await makeRESTRequest("HEAD", serverSpec);
}
if (response?.status !== 200) {
children.push(new OfflineTreeItem({ parent: element, label: name, id: name }, serverSpec.username || 'UnknownUser'));
} else {
children.push(new NamespacesTreeItem({ parent: element, label: name, id: name }, element.name, serverSpec.username || 'UnknownUser'));
Expand Down Expand Up @@ -458,11 +463,11 @@ async function serverNamespaces(element: ServerTreeItem, params?: any): Promise<
}

const response = await makeRESTRequest("GET", serverSpec);
if (!response || response.status !== 200) {
if (response?.status !== 200) {
children.push(new OfflineTreeItem({ parent: element, label: name, id: name }, serverSpec.username || 'UnknownUser'));
} else {
const serverApiVersion = response.data.result.content.api;
response.data.result.content.namespaces.map((namespace) => {
response.data.result.content.namespaces.map((namespace: string) => {
children.push(new NamespaceTreeItem({ parent: element, label: name, id: name }, namespace, name, serverApiVersion));
});
}
Expand Down Expand Up @@ -555,7 +560,7 @@ async function namespaceProjects(element: ProjectsTreeItem, params?: any): Promi
{ apiVersion: 1, namespace: params.ns, path: "/action/query" },
{ query: "SELECT Name, Description FROM %Studio.Project", parameters: [] }
);
if (response !== undefined) {
if (response?.status === 200) {
if (response.data.result.content === undefined) {
let message;
if (response.data.status?.errors[0]?.code === 5540) {
Expand Down Expand Up @@ -641,7 +646,7 @@ async function namespaceWebApps(element: ProjectsTreeItem, params?: any): Promis
serverSpec,
{ apiVersion: 1, namespace: "%SYS", path: `/cspapps/${params.ns}` }
);
if (response !== undefined) {
if (response?.status === 200) {
if (response.data.result.content === undefined) {
vscode.window.showErrorMessage(response.data.status.summary);
return undefined;
Expand Down

0 comments on commit 797655f

Please sign in to comment.