mirror of
https://github.com/Microsoft/vscode
synced 2024-09-18 01:58:27 +00:00
respect disablement state
This commit is contained in:
parent
eb0518fdb9
commit
dee65ce687
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue