mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-26 18:27:38 +01:00
Introduce auth-provider specific props & use it for social sign in for GitHub (#251649)
ref https://github.com/microsoft/vscode/issues/251648 NOTE: the server side is not quite ready. It doesn't redirect back to VS Code properly, but this should be good to go whenever that is.
This commit is contained in:
committed by
GitHub
parent
480485f0d0
commit
2fabac413d
@@ -12,6 +12,7 @@ import { ExperimentationTelemetry } from './common/experimentationService';
|
||||
import { Log } from './common/logger';
|
||||
import { crypto } from './node/crypto';
|
||||
import { TIMED_OUT_ERROR, USER_CANCELLATION_ERROR } from './common/errors';
|
||||
import { GitHubSocialSignInProvider, isSocialSignInProvider } from './flows';
|
||||
|
||||
interface SessionData {
|
||||
id: string;
|
||||
@@ -31,6 +32,20 @@ export enum AuthProviderType {
|
||||
githubEnterprise = 'github-enterprise'
|
||||
}
|
||||
|
||||
interface GitHubAuthenticationProviderOptions extends vscode.AuthenticationProviderSessionOptions {
|
||||
/**
|
||||
* This is specific to GitHub and is used to determine which social sign-in provider to use.
|
||||
* If not provided, the default (GitHub) is used which shows all options.
|
||||
*
|
||||
* Example: If you specify Google, then the sign-in flow will skip the initial page that asks you
|
||||
* to choose how you want to sign in and will directly take you to the Google sign-in page.
|
||||
*
|
||||
* This allows us to show "Continue with Google" buttons in the product, rather than always
|
||||
* leaving it up to the user to choose the social sign-in provider on the sign-in page.
|
||||
*/
|
||||
readonly provider?: GitHubSocialSignInProvider;
|
||||
}
|
||||
|
||||
export class UriEventHandler extends vscode.EventEmitter<vscode.Uri> implements vscode.UriHandler {
|
||||
private readonly _pendingNonces = new Map<string, string[]>();
|
||||
private readonly _codeExchangePromises = new Map<string, { promise: Promise<string>; cancel: vscode.EventEmitter<void> }>();
|
||||
@@ -306,7 +321,7 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
|
||||
this._logger.info(`Stored ${sessions.length} sessions!`);
|
||||
}
|
||||
|
||||
public async createSession(scopes: string[], options?: vscode.AuthenticationProviderSessionOptions): Promise<vscode.AuthenticationSession> {
|
||||
public async createSession(scopes: string[], options?: GitHubAuthenticationProviderOptions): Promise<vscode.AuthenticationSession> {
|
||||
try {
|
||||
// For GitHub scope list, order doesn't matter so we use a sorted scope to determine
|
||||
// if we've got a session already.
|
||||
@@ -325,9 +340,10 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
|
||||
|
||||
const sessions = await this._sessionsPromise;
|
||||
const loginWith = options?.account?.label;
|
||||
this._logger.info(`Logging in with '${loginWith ? loginWith : 'any'}' account...`);
|
||||
const signInProvider = isSocialSignInProvider(options?.provider) ? options.provider : undefined;
|
||||
this._logger.info(`Logging in with${signInProvider ? ` ${signInProvider}, ` : ''} '${loginWith ? loginWith : 'any'}' account...`);
|
||||
const scopeString = sortedScopes.join(' ');
|
||||
const token = await this._githubServer.login(scopeString, loginWith);
|
||||
const token = await this._githubServer.login(scopeString, signInProvider, loginWith);
|
||||
const session = await this.tokenToSession(token, scopes);
|
||||
this.afterSessionLoad(session);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user