mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
AzureAccountProvider & AzureAccountProviderService strict nulls (#20543)
This commit is contained in:
@@ -699,7 +699,7 @@ export interface RefreshToken extends AccountKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MultiTenantTokenResponse {
|
export interface MultiTenantTokenResponse {
|
||||||
[tenantId: string]: Token
|
[tenantId: string]: Token | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Token extends AccountKey {
|
export interface Token extends AccountKey {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const localize = nls.loadMessageBundle();
|
|||||||
export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disposable {
|
export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disposable {
|
||||||
private static readonly CONFIGURATION_SECTION = 'accounts.azure.auth';
|
private static readonly CONFIGURATION_SECTION = 'accounts.azure.auth';
|
||||||
private readonly authMappings = new Map<AzureAuthType, AzureAuth>();
|
private readonly authMappings = new Map<AzureAuthType, AzureAuth>();
|
||||||
private initComplete: Deferred<void, Error>;
|
private initComplete!: Deferred<void, Error>;
|
||||||
private initCompletePromise: Promise<void> = new Promise<void>((resolve, reject) => this.initComplete = { resolve, reject });
|
private initCompletePromise: Promise<void> = new Promise<void>((resolve, reject) => this.initComplete = { resolve, reject });
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -58,14 +58,15 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
|
|||||||
this.authMappings.clear();
|
this.authMappings.clear();
|
||||||
const configuration = vscode.workspace.getConfiguration(AzureAccountProvider.CONFIGURATION_SECTION);
|
const configuration = vscode.workspace.getConfiguration(AzureAccountProvider.CONFIGURATION_SECTION);
|
||||||
|
|
||||||
const codeGrantMethod: boolean = configuration.get('codeGrant');
|
const codeGrantMethod: boolean = configuration.get<boolean>('codeGrant', false);
|
||||||
const deviceCodeMethod: boolean = configuration.get('deviceCode');
|
const deviceCodeMethod: boolean = configuration.get<boolean>('deviceCode', false);
|
||||||
|
|
||||||
if (codeGrantMethod === true && !this.forceDeviceCode) {
|
if (codeGrantMethod === true && !this.forceDeviceCode) {
|
||||||
this.authMappings.set(AzureAuthType.AuthCodeGrant, new AzureAuthCodeGrant(metadata, tokenCache, context, uriEventHandler));
|
this.authMappings.set(AzureAuthType.AuthCodeGrant, new AzureAuthCodeGrant(metadata, tokenCache, context, uriEventHandler));
|
||||||
}
|
} else if (deviceCodeMethod === true || this.forceDeviceCode) {
|
||||||
if (deviceCodeMethod === true || this.forceDeviceCode) {
|
|
||||||
this.authMappings.set(AzureAuthType.DeviceCode, new AzureDeviceCode(metadata, tokenCache, context, uriEventHandler));
|
this.authMappings.set(AzureAuthType.DeviceCode, new AzureDeviceCode(metadata, tokenCache, context, uriEventHandler));
|
||||||
|
} else {
|
||||||
|
console.error('No authentication methods selected');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,12 +75,17 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
|
|||||||
return this.authMappings.values().next().value;
|
return this.authMappings.values().next().value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const authType: AzureAuthType = account?.properties?.azureAuthType;
|
const authType: AzureAuthType | undefined = account?.properties?.azureAuthType;
|
||||||
if (authType) {
|
if (authType) {
|
||||||
return this.authMappings.get(authType);
|
const authMapping = this.authMappings.get(authType);
|
||||||
} else {
|
if (authMapping) {
|
||||||
return this.authMappings.values().next().value;
|
return authMapping;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (this.authMappings.size === 0) {
|
||||||
|
throw new Error('No authentication mappings selected');
|
||||||
|
}
|
||||||
|
return this.authMappings.values().next().value;
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize(storedAccounts: AzureAccount[]): Thenable<AzureAccount[]> {
|
initialize(storedAccounts: AzureAccount[]): Thenable<AzureAccount[]> {
|
||||||
|
|||||||
@@ -30,22 +30,15 @@ export class AzureAccountProviderService implements vscode.Disposable {
|
|||||||
|
|
||||||
// MEMBER VARIABLES ////////////////////////////////////////////////////////
|
// MEMBER VARIABLES ////////////////////////////////////////////////////////
|
||||||
private _disposables: vscode.Disposable[] = [];
|
private _disposables: vscode.Disposable[] = [];
|
||||||
private _accountDisposals: { [accountProviderId: string]: vscode.Disposable };
|
private _accountDisposals: { [accountProviderId: string]: vscode.Disposable } = {};
|
||||||
private _accountProviders: { [accountProviderId: string]: azdata.AccountProvider };
|
private _accountProviders: { [accountProviderId: string]: azdata.AccountProvider } = {};
|
||||||
private _credentialProvider: azdata.CredentialProvider;
|
private _credentialProvider: azdata.CredentialProvider | undefined = undefined;
|
||||||
private _configChangePromiseChain: Thenable<void>;
|
private _configChangePromiseChain: Thenable<void> = Promise.resolve();
|
||||||
private _currentConfig: vscode.WorkspaceConfiguration;
|
private _currentConfig: vscode.WorkspaceConfiguration | undefined = undefined;
|
||||||
private _event: events.EventEmitter;
|
private _event: events.EventEmitter = new events.EventEmitter();
|
||||||
private readonly _uriEventHandler: UriEventHandler;
|
private readonly _uriEventHandler: UriEventHandler = new UriEventHandler();
|
||||||
|
|
||||||
constructor(private _context: vscode.ExtensionContext, private _userStoragePath: string) {
|
constructor(private _context: vscode.ExtensionContext, private _userStoragePath: string) {
|
||||||
this._accountDisposals = {};
|
|
||||||
this._accountProviders = {};
|
|
||||||
this._configChangePromiseChain = Promise.resolve();
|
|
||||||
this._currentConfig = null;
|
|
||||||
this._event = new events.EventEmitter();
|
|
||||||
|
|
||||||
this._uriEventHandler = new UriEventHandler();
|
|
||||||
this._disposables.push(vscode.window.registerUriHandler(this._uriEventHandler));
|
this._disposables.push(vscode.window.registerUriHandler(this._uriEventHandler));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,6 +141,9 @@ export class AzureAccountProviderService implements vscode.Disposable {
|
|||||||
try {
|
try {
|
||||||
const noSystemKeychain = vscode.workspace.getConfiguration('azure').get<boolean>('noSystemKeychain');
|
const noSystemKeychain = vscode.workspace.getConfiguration('azure').get<boolean>('noSystemKeychain');
|
||||||
let tokenCacheKey = `azureTokenCache-${provider.metadata.id}`;
|
let tokenCacheKey = `azureTokenCache-${provider.metadata.id}`;
|
||||||
|
if (!this._credentialProvider) {
|
||||||
|
throw new Error('Credential provider not registered');
|
||||||
|
}
|
||||||
let simpleTokenCache = new SimpleTokenCache(tokenCacheKey, this._userStoragePath, noSystemKeychain, this._credentialProvider);
|
let simpleTokenCache = new SimpleTokenCache(tokenCacheKey, this._userStoragePath, noSystemKeychain, this._credentialProvider);
|
||||||
await simpleTokenCache.init();
|
await simpleTokenCache.init();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user