Skip to content

Commit 6e31f82

Browse files
authored
Merge pull request #94 from Microsoft/shana/login
Hook up webflow auth during credential checks
2 parents e979db3 + d62e444 commit 6e31f82

16 files changed

Lines changed: 938 additions & 482 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,5 @@ ASALocalRun/
332332

333333
out
334334
node_modules
335-
media
335+
media
336+
.DS_Store

package-lock.json

Lines changed: 28 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,27 @@
2828
"type": "object",
2929
"title": "GitHub configuration",
3030
"properties": {
31-
"github.username": {
32-
"type": [
33-
"string",
34-
"null"
35-
],
36-
"default": null,
37-
"description": "The username to use when accessing GitHub. The default is to consult the Git credential manager."
38-
},
39-
"github.host": {
40-
"type": "string",
41-
"default": "github.com",
42-
"description": "The host name to access GitHub. Change this to your GitHub Enterprise host."
43-
},
44-
"github.accessToken": {
45-
"type": [
46-
"string",
47-
"null"
48-
],
49-
"default": null,
50-
"description": "GitHub access token."
31+
"github.hosts": {
32+
"type": "array",
33+
"default": [],
34+
"description": "Host tokens",
35+
"items": {
36+
"type": "object",
37+
"properties": {
38+
"host": {
39+
"type": "string",
40+
"description": "The host name of the GitHub server (for eg., 'https://github.com')"
41+
},
42+
"username": {
43+
"type": "string",
44+
"description": "The username to access GitHub"
45+
},
46+
"token": {
47+
"type": "string",
48+
"description": "GitHub access token with the following scopes: read:user, user:email, repo, write:discussion"
49+
}
50+
}
51+
}
5152
}
5253
}
5354
},
@@ -239,9 +240,11 @@
239240
"iconv-lite": "0.4.23",
240241
"vscode": "^1.1.18",
241242
"@octokit/rest": "^15.9.5",
243+
"@types/ws": "^5.1.2",
242244
"markdown-it": "^8.4.0",
243245
"git-credential-node": "^1.1.0",
244246
"tmp": "^0.0.31",
245-
"moment": "^2.22.1"
247+
"moment": "^2.22.1",
248+
"ws": "^6.0.0"
246249
}
247250
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as vscode from 'vscode';
2+
3+
export interface IHostConfiguration {
4+
host: string;
5+
username: string | undefined;
6+
token: string | undefined;
7+
}
8+
9+
export const HostHelper = class {
10+
public static getApiHost(host: IHostConfiguration | vscode.Uri): vscode.Uri {
11+
const hostUri: vscode.Uri = host instanceof vscode.Uri ? host : vscode.Uri.parse(host.host);
12+
if (hostUri.authority === 'github.com') {
13+
return vscode.Uri.parse('https://api.github.com');
14+
} else {
15+
return vscode.Uri.parse(`${hostUri.scheme}://${hostUri.authority}`);
16+
}
17+
}
18+
19+
public static getApiPath(host: IHostConfiguration | vscode.Uri, path: string): string {
20+
const hostUri: vscode.Uri = host instanceof vscode.Uri ? host : vscode.Uri.parse(host.host);
21+
if (hostUri.authority === 'github.com') {
22+
return path;
23+
} else {
24+
return `/api/v3${path}`;
25+
}
26+
}
27+
};
28+
29+
export interface IConfiguration extends IHostConfiguration {
30+
onDidChange: vscode.Event<IConfiguration>;
31+
}
32+
33+
export class Configuration implements IConfiguration {
34+
public username: string | undefined;
35+
public token: string | undefined;
36+
public onDidChange: vscode.Event<IConfiguration>;
37+
private _emitter: vscode.EventEmitter<IConfiguration>;
38+
39+
constructor(public host: string) {
40+
this._emitter = new vscode.EventEmitter<IConfiguration>();
41+
this.onDidChange = this._emitter.event;
42+
}
43+
44+
public update(username: string | undefined, token: string | undefined, raiseEvent: boolean = true): void {
45+
if (username !== this.username || token !== this.token) {
46+
this.username = username;
47+
this.token = token;
48+
if (raiseEvent) {
49+
this._emitter.fire(this);
50+
}
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)