Properly reference the vscode.proposed.d.ts typings from the account extension

This commit is contained in:
Rachel Macfarlane
2020-02-06 10:01:36 -08:00
parent e3b19d2071
commit 4801814872
7 changed files with 32 additions and 92 deletions
+3 -4
View File
@@ -17,14 +17,13 @@
"main": "./out/extension.js",
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./"
"compile": "gulp compile-extension:vscode-account",
"watch": "gulp watch-extension:vscode-account"
},
"devDependencies": {
"typescript": "^3.7.4",
"tslint": "^5.12.1",
"@types/node": "^10.12.21",
"@types/keytar": "^4.0.1",
"@types/vscode": "^1.41.0"
"@types/keytar": "^4.0.1"
}
}
+6 -6
View File
@@ -22,7 +22,7 @@ interface IToken {
accessToken: string;
refreshToken: string;
displayName: string;
accountName: string;
scope: string;
sessionId: string; // The account id + the scope
}
@@ -170,11 +170,11 @@ export class AzureActiveDirectoryService {
}, 1000 * 30);
}
private convertToSession(token: IToken): vscode.Session {
private convertToSession(token: IToken): vscode.AuthenticationSession {
return {
id: token.sessionId,
accessToken: token.accessToken,
displayName: token.displayName,
accountName: token.accountName,
scopes: token.scope.split(' ')
};
}
@@ -188,7 +188,7 @@ export class AzureActiveDirectoryService {
}
}
get sessions(): vscode.Session[] {
get sessions(): vscode.AuthenticationSession[] {
return this._tokens.map(token => this.convertToSession(token));
}
@@ -288,7 +288,7 @@ export class AzureActiveDirectoryService {
});
vscode.env.openExternal(uri);
const timeoutPromise = new Promise((resolve: (value: IToken) => void, reject) => {
const timeoutPromise = new Promise((_: (value: IToken) => void, reject) => {
const wait = setTimeout(() => {
clearTimeout(wait);
reject('Login timed out.');
@@ -362,7 +362,7 @@ export class AzureActiveDirectoryService {
refreshToken: json.refresh_token,
scope,
sessionId: `${claims.tid}/${(claims.oid || (claims.altsecid || '' + claims.ipd || ''))}/${scope}`,
displayName: claims.email || claims.unique_name || 'user@example.com'
accountName: claims.email || claims.unique_name || 'user@example.com'
};
}
+1 -1
View File
@@ -6,7 +6,7 @@
import * as vscode from 'vscode';
import { AzureActiveDirectoryService, onDidChangeSessions } from './AADHelper';
export async function activate(context: vscode.ExtensionContext) {
export async function activate(_: vscode.ExtensionContext) {
const loginService = new AzureActiveDirectoryService();
+8 -2
View File
@@ -7,6 +7,7 @@
// how we load it
import * as keytarType from 'keytar';
import { env } from 'vscode';
import Logger from './logger';
function getKeytar(): Keytar | undefined {
try {
@@ -44,22 +45,27 @@ export class Keychain {
return await this.keytar.setPassword(SERVICE_ID, ACCOUNT_ID, token);
} catch (e) {
// Ignore
Logger.error(`Setting token failed: ${e}`);
}
}
async getToken() {
async getToken(): Promise<string | null | undefined> {
try {
return await this.keytar.getPassword(SERVICE_ID, ACCOUNT_ID);
} catch (e) {
// Ignore
Logger.error(`Getting token failed: ${e}`);
return Promise.resolve(undefined);
}
}
async deleteToken() {
async deleteToken(): Promise<boolean | undefined> {
try {
return await this.keytar.deletePassword(SERVICE_ID, ACCOUNT_ID);
} catch (e) {
// Ignore
Logger.error(`Deleting token failed: ${e}`);
return Promise.resolve(undefined);
}
}
}
+7
View File
@@ -0,0 +1,7 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/// <reference path='../../../../src/vs/vscode.d.ts'/>
/// <reference path='../../../../src/vs/vscode.proposed.d.ts'/>
-61
View File
@@ -1,61 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* This is the place for API experiments and proposals.
* These API are NOT stable and subject to change. They are only available in the Insiders
* distribution and CANNOT be used in published extensions.
*
* To test these API in local environment:
* - Use Insiders release of VS Code.
* - Add `"enableProposedApi": true` to your package.json.
* - Copy this file to your project.
*/
declare module 'vscode' {
export interface Session {
id: string;
accessToken: string;
displayName: string;
scopes: string[]
}
export interface AuthenticationProvider {
readonly id: string;
readonly displayName: string;
readonly onDidChangeSessions: Event<void>;
/**
* Returns an array of current sessions.
*/
getSessions(): Promise<ReadonlyArray<Session>>;
/**
* Prompts a user to login.
*/
login(scopes: string[]): Promise<Session>;
logout(sessionId: string): Promise<void>;
}
export namespace authentication {
export function registerAuthenticationProvider(provider: AuthenticationProvider): Disposable;
/**
* Fires with the provider id that was registered or unregistered.
*/
export const onDidRegisterAuthenticationProvider: Event<string>;
export const onDidUnregisterAuthenticationProvider: Event<string>;
export const providers: ReadonlyArray<AuthenticationProvider>;
}
// #region Ben - extension auth flow (desktop+web)
export namespace env {
export function asExternalUri(target: Uri): Thenable<Uri>
}
}
+7 -18
View File
@@ -1,24 +1,13 @@
{
"extends": "../shared.tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"lib": [
"es6",
"es2016",
"dom"
],
"outDir": "./out",
"experimentalDecorators": true,
"typeRoots": [
"node_modules/@types",
"src/typings"
],
"sourceMap": true,
"rootDir": "src",
"strict": true,
"noImplicitAny": true
"./node_modules/@types"
]
},
"exclude": [
"node_modules",
".vscode-test"
"include": [
"src/**/*"
]
}