Skip to content

Commit 6eaff51

Browse files
Preserve case of username in scopes[1] so getSession caller can obtain it exactly (required when case-sensitive external authorization is being used) (#281)
* Preserve case of username in `session.account.id` so `getSession` caller can obtain it * Update a line of README code sample * Support case-sensitive usernames * Convert indenting to tabs (standard for this project) * No longer lowercase userName in account.id * Revert README usage example code change (no longer needed) * Remove a stray `toLowerCase()` * Revert an obsolete change
1 parent f3f2dda commit 6eaff51

File tree

5 files changed

+376
-377
lines changed

5 files changed

+376
-377
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ To obtain the password with which to connect, use code like this which will also
263263
session = await vscode.authentication.getSession(serverManager.AUTHENTICATION_PROVIDER, scopes, { createIfNone: true, account });
264264
}
265265
if (session) {
266-
serverSpec.username = session.scopes[1];
266+
serverSpec.username = session.scopes[1].toLowerCase() === "unknownuser" ? "" : session.scopes[1];
267267
serverSpec.password = session.accessToken;
268268
}
269269
}

src/authenticationProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ export class ServerManagerAuthenticationProvider implements AuthenticationProvid
6363

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

6969
if (options.account) {
7070
const accountParts = options.account.id.split("/");
7171
const serverName = accountParts.shift();
72-
const userName = accountParts.join('/').toLowerCase();
72+
const userName = accountParts.join('/');
7373
if (serverName && userName) {
74-
sessions = sessions.filter((session) => session.scopes[0] === serverName && session.scopes[1] === userName);
74+
sessions = sessions.filter((session) => session.scopes[0] === serverName && session.scopes[1].toLowerCase() === userName.toLowerCase());
7575
}
7676
}
7777

src/authenticationSession.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ export class ServerManagerAuthenticationSession implements AuthenticationSession
1111
public readonly userName: string,
1212
password: string,
1313
) {
14-
const canonicalUserName = userName.toLowerCase();
1514
this.id = ServerManagerAuthenticationProvider.sessionId(serverName, userName);
1615
this.accessToken = password;
17-
this.account = { id: `${serverName}/${canonicalUserName}`, label: `${userName} on ${serverName}` };
18-
this.scopes = [serverName, canonicalUserName];
16+
this.account = { id: `${serverName}/${userName}`, label: `${userName} on ${serverName}` };
17+
this.scopes = [serverName, userName];
1918
}
2019
}

0 commit comments

Comments
 (0)