add additional logging around github auth

This commit is contained in:
Tyler Leonhardt 2021-06-28 16:27:52 -07:00
parent c4cde2147a
commit 4a011b5297
No known key found for this signature in database
GPG key ID: 1BC2B6244363E77E
4 changed files with 14 additions and 2 deletions

View file

@ -46,7 +46,11 @@ export class Keychain {
async getToken(): Promise<string | null | undefined> {
try {
return await this.context.secrets.get(this.serviceId);
const secret = await this.context.secrets.get(this.serviceId);
if (secret && secret !== '[]') {
Logger.trace('Token acquired from secret storage.');
}
return secret;
} catch (e) {
// Ignore
Logger.error(`Getting token failed: ${e}`);
@ -73,6 +77,7 @@ export class Keychain {
const oldValue = await keytar.getPassword(`${vscode.env.uriScheme}-github.login`, 'account');
if (oldValue) {
Logger.trace('Attempting to migrate from keytar to secret store...');
await this.setToken(oldValue);
await keytar.deletePassword(`${vscode.env.uriScheme}-github.login`, 'account');
}

View file

@ -24,6 +24,10 @@ class Log {
return data.toString();
}
public trace(message: string, data?: any): void {
this.logLevel('Trace', message, data);
}
public info(message: string, data?: any): void {
this.logLevel('Info', message, data);
}

View file

@ -86,6 +86,7 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
try {
await this._githubServer.getUserInfo(session.accessToken);
this.afterTokenLoad(session.accessToken);
Logger.info(`Verified sesion with the following scopes: ${session.scopes}`);
verifiedSessions.push(session);
} catch (e) {
// Remove sessions that return unauthorized response
@ -156,6 +157,7 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
userInfo = await this._githubServer.getUserInfo(session.accessToken);
}
Logger.trace(`Read the following session from the keychain with the following scopes: ${session.scopes}`);
return {
id: session.id,
account: {

View file

@ -20,6 +20,7 @@ const AUTH_RELAY_SERVER = 'vscode-auth.github.com';
class UriEventHandler extends vscode.EventEmitter<vscode.Uri> implements vscode.UriHandler {
public handleUri(uri: vscode.Uri) {
Logger.trace('Handling Uri...');
this.fire(uri);
}
}
@ -54,7 +55,7 @@ export class GitHubServer {
}
public async login(scopes: string): Promise<string> {
Logger.info('Logging in...');
Logger.info(`Logging in for the following scopes: ${scopes}`);
this.updateStatusBarItem(true);
const state = uuid();