Skip to content

Commit

Permalink
move to APPLICATION for all auth usages (microsoft#153381)
Browse files Browse the repository at this point in the history
move to APPLICATION for all auth since auth is really done machine wide. ref microsoft#152679
  • Loading branch information
TylerLeonhardt authored Jun 27, 2022
1 parent 0a3ca02 commit b129227
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/vs/workbench/api/browser/mainThreadAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class MainThreadAuthenticationProvider extends Disposable implements IAut
quickPick.onDidAccept(() => {
const updatedAllowedList = quickPick.items
.map(i => (i as TrustedExtensionsQuickPickItem).extension);
this.storageService.store(`${this.id}-${accountName}`, JSON.stringify(updatedAllowedList), StorageScope.PROFILE, StorageTarget.USER);
this.storageService.store(`${this.id}-${accountName}`, JSON.stringify(updatedAllowedList), StorageScope.APPLICATION, StorageTarget.USER);

quickPick.dispose();
});
Expand Down Expand Up @@ -116,7 +116,7 @@ export class MainThreadAuthenticationProvider extends Disposable implements IAut
const removeSessionPromises = sessions.map(session => this.removeSession(session.id));
await Promise.all(removeSessionPromises);
removeAccountUsage(this.storageService, this.id, accountName);
this.storageService.remove(`${this.id}-${accountName}`, StorageScope.PROFILE);
this.storageService.remove(`${this.id}-${accountName}`, StorageScope.APPLICATION);
}
}

Expand Down Expand Up @@ -201,7 +201,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu

private async setTrustedExtensionAndAccountPreference(providerId: string, accountName: string, extensionId: string, extensionName: string, sessionId: string): Promise<void> {
this.authenticationService.updatedAllowedExtension(providerId, accountName, extensionId, extensionName, true);
this.storageService.store(`${extensionName}-${providerId}`, sessionId, StorageScope.PROFILE, StorageTarget.MACHINE);
this.storageService.store(`${extensionName}-${providerId}`, sessionId, StorageScope.APPLICATION, StorageTarget.MACHINE);

}

Expand All @@ -224,9 +224,9 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
if (!options.forceNewSession && sessions.length) {
if (supportsMultipleAccounts) {
if (options.clearSessionPreference) {
this.storageService.remove(`${extensionName}-${providerId}`, StorageScope.PROFILE);
this.storageService.remove(`${extensionName}-${providerId}`, StorageScope.APPLICATION);
} else {
const existingSessionPreference = this.storageService.get(`${extensionName}-${providerId}`, StorageScope.PROFILE);
const existingSessionPreference = this.storageService.get(`${extensionName}-${providerId}`, StorageScope.APPLICATION);
if (existingSessionPreference) {
const matchingSession = sessions.find(session => session.id === existingSessionPreference);
if (matchingSession && this.authenticationService.isAccessAllowed(providerId, matchingSession.account.label, extensionId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const FIRST_PARTY_ALLOWED_EXTENSIONS = [

export function readAccountUsages(storageService: IStorageService, providerId: string, accountName: string,): IAccountUsage[] {
const accountKey = `${providerId}-${accountName}-usages`;
const storedUsages = storageService.get(accountKey, StorageScope.PROFILE);
const storedUsages = storageService.get(accountKey, StorageScope.APPLICATION);
let usages: IAccountUsage[] = [];
if (storedUsages) {
try {
Expand All @@ -62,7 +62,7 @@ export function readAccountUsages(storageService: IStorageService, providerId: s

export function removeAccountUsage(storageService: IStorageService, providerId: string, accountName: string): void {
const accountKey = `${providerId}-${accountName}-usages`;
storageService.remove(accountKey, StorageScope.PROFILE);
storageService.remove(accountKey, StorageScope.APPLICATION);
}

export function addAccountUsage(storageService: IStorageService, providerId: string, accountName: string, extensionId: string, extensionName: string) {
Expand All @@ -84,7 +84,7 @@ export function addAccountUsage(storageService: IStorageService, providerId: str
});
}

storageService.store(accountKey, JSON.stringify(usages), StorageScope.PROFILE, StorageTarget.MACHINE);
storageService.store(accountKey, JSON.stringify(usages), StorageScope.APPLICATION, StorageTarget.MACHINE);
}

export type AuthenticationSessionInfo = { readonly id: string; readonly accessToken: string; readonly providerId: string; readonly canSignOut?: boolean };
Expand Down Expand Up @@ -112,7 +112,7 @@ export interface AllowedExtension {
export function readAllowedExtensions(storageService: IStorageService, providerId: string, accountName: string): AllowedExtension[] {
let trustedExtensions: AllowedExtension[] = [];
try {
const trustedExtensionSrc = storageService.get(`${providerId}-${accountName}`, StorageScope.PROFILE);
const trustedExtensionSrc = storageService.get(`${providerId}-${accountName}`, StorageScope.APPLICATION);
if (trustedExtensionSrc) {
trustedExtensions = JSON.parse(trustedExtensionSrc);
}
Expand Down Expand Up @@ -410,7 +410,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
allowList[index].allowed = isAllowed;
}

await this.storageService.store(`${providerId}-${accountName}`, JSON.stringify(allowList), StorageScope.PROFILE, StorageTarget.USER);
await this.storageService.store(`${providerId}-${accountName}`, JSON.stringify(allowList), StorageScope.APPLICATION, StorageTarget.USER);
}

async showGetSessionPrompt(providerId: string, accountName: string, extensionId: string, extensionName: string): Promise<boolean> {
Expand Down Expand Up @@ -475,7 +475,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
this.updatedAllowedExtension(providerId, accountName, extensionId, extensionName, true);

this.removeAccessRequest(providerId, extensionId);
this.storageService.store(`${extensionName}-${providerId}`, session.id, StorageScope.PROFILE, StorageTarget.MACHINE);
this.storageService.store(`${extensionName}-${providerId}`, session.id, StorageScope.APPLICATION, StorageTarget.MACHINE);

quickPick.dispose();
resolve(session);
Expand Down Expand Up @@ -615,7 +615,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
this.updatedAllowedExtension(providerId, session.account.label, extensionId, extensionName, true);

// And also set it as the preferred account for the extension
storageService.store(`${extensionName}-${providerId}`, session.id, StorageScope.PROFILE, StorageTarget.MACHINE);
storageService.store(`${extensionName}-${providerId}`, session.id, StorageScope.APPLICATION, StorageTarget.MACHINE);
}
});

Expand Down

0 comments on commit b129227

Please sign in to comment.