mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
Pass scopes through to authentication providers
This commit is contained in:
@@ -71,3 +71,25 @@ export async function promiseFromEvent<T, U>(
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function arrayEquals<T>(one: ReadonlyArray<T> | undefined, other: ReadonlyArray<T> | undefined, itemEquals: (a: T, b: T) => boolean = (a, b) => a === b): boolean {
|
||||
if (one === other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!one || !other) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (one.length !== other.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0, len = one.length; i < len; i++) {
|
||||
if (!itemEquals(one[i], other[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
context.subscriptions.push(vscode.authentication.registerAuthenticationProvider('github', 'GitHub', {
|
||||
onDidChangeSessions: onDidChangeSessions.event,
|
||||
getSessions: () => Promise.resolve(loginService.sessions),
|
||||
getAllSessions: () => Promise.resolve(loginService.sessions),
|
||||
getSessions: (scopes: string[]) => loginService.getSessions(scopes),
|
||||
login: async (scopeList: string[]) => {
|
||||
try {
|
||||
/* __GDPR__
|
||||
|
||||
@@ -8,6 +8,7 @@ import { v4 as uuid } from 'uuid';
|
||||
import { Keychain } from './common/keychain';
|
||||
import { GitHubServer, NETWORK_ERROR } from './githubServer';
|
||||
import Logger from './common/logger';
|
||||
import { arrayEquals } from './common/utils';
|
||||
|
||||
export const onDidChangeSessions = new vscode.EventEmitter<vscode.AuthenticationProviderAuthenticationSessionsChangeEvent>();
|
||||
|
||||
@@ -43,6 +44,10 @@ export class GitHubAuthenticationProvider {
|
||||
context.subscriptions.push(context.secrets.onDidChange(() => this.checkForUpdates()));
|
||||
}
|
||||
|
||||
async getSessions(scopes: string[]): Promise<vscode.AuthenticationSession[]> {
|
||||
return this._sessions.filter(session => arrayEquals(session.scopes, scopes));
|
||||
}
|
||||
|
||||
private async verifySessions(): Promise<void> {
|
||||
const verifiedSessions: vscode.AuthenticationSession[] = [];
|
||||
const verificationPromises = this._sessions.map(async session => {
|
||||
|
||||
Reference in New Issue
Block a user