-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #670 from Hi-Windom/v0.32
V0.32
- Loading branch information
Showing
68 changed files
with
4,089 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,4 @@ yarn.lock | |
/app/out | ||
/app/dist-electron | ||
**/node_modules | ||
**.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as vscode from 'vscode'; | ||
import * as Octokit from '@octokit/rest'; | ||
|
||
const GITHUB_AUTH_PROVIDER_ID = 'github'; | ||
// The GitHub Authentication Provider accepts the scopes described here: | ||
// https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/ | ||
const SCOPES = ['user:email']; | ||
|
||
export class Credentials { | ||
private octokit: Octokit.Octokit | undefined; | ||
|
||
async initialize(context: vscode.ExtensionContext): Promise<void> { | ||
this.registerListeners(context); | ||
await this.setOctokit(); | ||
} | ||
|
||
private async setOctokit() { | ||
/** | ||
* By passing the `createIfNone` flag, a numbered badge will show up on the accounts activity bar icon. | ||
* An entry for the sample extension will be added under the menu to sign in. This allows quietly | ||
* prompting the user to sign in. | ||
* */ | ||
const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone: false }); | ||
|
||
if (session) { | ||
this.octokit = new Octokit.Octokit({ | ||
auth: session.accessToken | ||
}); | ||
|
||
return; | ||
} | ||
|
||
this.octokit = undefined; | ||
} | ||
|
||
registerListeners(context: vscode.ExtensionContext): void { | ||
/** | ||
* Sessions are changed when a user logs in or logs out. | ||
*/ | ||
context.subscriptions.push(vscode.authentication.onDidChangeSessions(async e => { | ||
if (e.provider.id === GITHUB_AUTH_PROVIDER_ID) { | ||
await this.setOctokit(); | ||
} | ||
})); | ||
} | ||
|
||
async getOctokit(): Promise<Octokit.Octokit> { | ||
if (this.octokit) { | ||
return this.octokit; | ||
} | ||
|
||
/** | ||
* When the `createIfNone` flag is passed, a modal dialog will be shown asking the user to sign in. | ||
* Note that this can throw if the user clicks cancel. | ||
*/ | ||
const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone: true }); | ||
this.octokit = new Octokit.Octokit({ | ||
auth: session.accessToken | ||
}); | ||
|
||
return this.octokit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.