respect disablement state

This commit is contained in:
Sandeep Somavarapu 2019-09-27 16:39:59 +02:00
parent eb0518fdb9
commit dee65ce687
2 changed files with 20 additions and 6 deletions

View file

@ -36,19 +36,31 @@ export class AuthTokenService extends Disposable implements IAuthTokenService {
}
getToken(): Promise<string | null> {
if (this.status === AuthTokenStatus.Disabled) {
throw new Error('Not enabled');
}
return this.credentialsService.getPassword(SERVICE_NAME, ACCOUNT);
}
async updateToken(token: string): Promise<void> {
if (this.status === AuthTokenStatus.Disabled) {
throw new Error('Not enabled');
}
await this.credentialsService.setPassword(SERVICE_NAME, ACCOUNT, token);
this.setStatus(AuthTokenStatus.Active);
}
async refreshToken(): Promise<void> {
if (this.status === AuthTokenStatus.Disabled) {
throw new Error('Not enabled');
}
await this.deleteToken();
}
async deleteToken(): Promise<void> {
if (this.status === AuthTokenStatus.Disabled) {
throw new Error('Not enabled');
}
await this.credentialsService.deletePassword(SERVICE_NAME, ACCOUNT);
this.setStatus(AuthTokenStatus.Inactive);
}

View file

@ -12,7 +12,7 @@ import { URI } from 'vs/base/common/uri';
import { joinPath } from 'vs/base/common/resources';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IHeaders, IRequestOptions, IRequestContext } from 'vs/base/parts/request/common/request';
import { IAuthTokenService } from 'vs/platform/auth/common/auth';
import { IAuthTokenService, AuthTokenStatus } from 'vs/platform/auth/common/auth';
export class UserDataSyncStoreService extends Disposable implements IUserDataSyncStoreService {
@ -100,12 +100,14 @@ export class UserDataSyncStoreService extends Disposable implements IUserDataSyn
}
private async request(options: IRequestOptions, token: CancellationToken): Promise<IRequestContext> {
const authToken = await this.authTokenService.getToken();
if (!authToken) {
return Promise.reject(new Error('No Auth Token Available.'));
if (this.authTokenService.status !== AuthTokenStatus.Disabled) {
const authToken = await this.authTokenService.getToken();
if (!authToken) {
return Promise.reject(new Error('No Auth Token Available.'));
}
options.headers = options.headers || {};
options.headers['authorization'] = `Bearer ${authToken}`;
}
options.headers = options.headers || {};
options.headers['authorization'] = `Bearer ${authToken}`;
const context = await this.requestService.request(options, token);