Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unusable tenants #9921

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about other general errors that occur while trying to refresh? Is the error not something we can check for more specifically?

It might be worth thinking about asking the user whether they want us to remove the tenant so that at least they're aware it's happening. (I'm a little worried most users won't know what that means though so not sure what the best approach is here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Synced offline

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked offline - going to get this in and then if users have an issue with missing resources can look into exposing this more publically to them. But it should be enough of an edge case that this is fine to just do and log in the console.

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