Skip to content

Preserve case of username in scopes[1] so getSession caller can obtain it exactly (required when case-sensitive external authorization is being used) #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 27, 2025
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ To obtain the password with which to connect, use code like this which will also
session = await vscode.authentication.getSession(serverManager.AUTHENTICATION_PROVIDER, scopes, { createIfNone: true, account });
}
if (session) {
serverSpec.username = session.scopes[1];
serverSpec.username = session.scopes[1].toLowerCase() === "unknownuser" ? "" : session.scopes[1];
serverSpec.password = session.accessToken;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/authenticationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ export class ServerManagerAuthenticationProvider implements AuthenticationProvid

// Filter to return only those that match all supplied scopes, which are positional and case-insensitive.
for (let index = 0; index < scopes.length; index++) {
sessions = sessions.filter((session) => session.scopes[index] === scopes[index].toLowerCase());
sessions = sessions.filter((session) => session.scopes[index].toLowerCase() === scopes[index].toLowerCase());
}

if (options.account) {
const accountParts = options.account.id.split("/");
const serverName = accountParts.shift();
const userName = accountParts.join('/').toLowerCase();
const userName = accountParts.join('/');
if (serverName && userName) {
sessions = sessions.filter((session) => session.scopes[0] === serverName && session.scopes[1] === userName);
sessions = sessions.filter((session) => session.scopes[0] === serverName && session.scopes[1].toLowerCase() === userName.toLowerCase());
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/authenticationSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ export class ServerManagerAuthenticationSession implements AuthenticationSession
public readonly userName: string,
password: string,
) {
const canonicalUserName = userName.toLowerCase();
this.id = ServerManagerAuthenticationProvider.sessionId(serverName, userName);
this.accessToken = password;
this.account = { id: `${serverName}/${canonicalUserName}`, label: `${userName} on ${serverName}` };
this.scopes = [serverName, canonicalUserName];
this.account = { id: `${serverName}/${userName}`, label: `${userName} on ${serverName}` };
this.scopes = [serverName, userName];
}
}
Loading