Skip to content

Commit

Permalink
Remove unusable tenants (#9921)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir Omidi authored Apr 9, 2020
1 parent 23f1a08 commit 510c126
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions extensions/azurecore/src/account-provider/auths/azureAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,14 @@ export abstract class AzureAuth implements vscode.Disposable {
console.log('Base token was empty, account is stale.');
return undefined;
}

try {
await this.refreshAccessToken(account.key, baseToken.refreshToken, tenant, resource);
} catch (ex) {
console.log(ex);
account.isStale = true;
return undefined;
console.log(`Could not refresh access token for ${JSON.stringify(tenant)} - silently removing the tenant from the user's account.`);
azureAccount.properties.tenants = azureAccount.properties.tenants.filter(t => t.id !== tenant.id);
console.log(ex, ex?.data, ex?.response);
continue;
}

cachedTokens = await this.getCachedToken(account.key, resource.id, tenant.id);
Expand All @@ -243,9 +245,12 @@ export abstract class AzureAuth implements vscode.Disposable {

if (azureAccount.properties.subscriptions) {
azureAccount.properties.subscriptions.forEach(subscription => {
response[subscription.id] = {
...response[subscription.tenantId]
};
// Make sure that tenant has information populated.
if (response[subscription.tenantId]) {
response[subscription.id] = {
...response[subscription.tenantId]
};
}
});
}

Expand Down

0 comments on commit 510c126

Please sign in to comment.