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

New Azure Auth Provider #9664

Merged
merged 16 commits into from
Mar 23, 2020
Merged

New Azure Auth Provider #9664

merged 16 commits into from
Mar 23, 2020

Conversation

aaomidi
Copy link
Contributor

@aaomidi aaomidi commented Mar 18, 2020

#9618

This is the largest chunk of the PRs we're looking for this feature.

@aaomidi aaomidi requested a review from Charles-Gagnon March 18, 2020 20:30
@github-actions
Copy link

Coverage Status

Coverage increased (+0.2%) to 30.287% when pulling 43d9ed0 on amir/azureAuth/newProvider into 166f0d1 on master.

@aaomidi aaomidi requested review from kburtram and abist March 19, 2020 01:09
@aaomidi aaomidi requested a review from alanrenmsft March 20, 2020 00:32
import { MemoryDatabase } from '../utils/memoryDatabase';
const localize = nls.loadMessageBundle();

export interface AccountKey {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if those comments are useful unless they provide some information about the fields

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True haha

Copy link
Contributor

Choose a reason for hiding this comment

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

Similar cases in the interfaces below :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other ones seem pretty self explanatory :D

} catch (err) {
console.dir(err);
const msg = localize('azure.noToken', "Retrieving the token failed.");
throw new Error(msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you missed showing the localized error to the user here instead of throwing the localized error.

@alanrenmsft
Copy link
Contributor

could you please provide more description for this PR?

@aaomidi
Copy link
Contributor Author

aaomidi commented Mar 20, 2020

The PR here should provide the information @alanrenmsft #9618

This PR is essentially that one just split into multiple chunks. This provides a new Azure Account Provider that is far less error prone and is ready to upgrade to MSAL when we're unblocked from doing so.

@aaomidi aaomidi requested review from abist and alanrenmsft March 20, 2020 19:49

if (!accessToken || !refreshToken) {
console.log('Access or refresh token were undefined');
const msg = localize('azure.refreshTokenError', "Error when refreshing your account.");
Copy link
Contributor

Choose a reason for hiding this comment

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

User error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm not this one. It's called from two places and one of them I don't want to show it to the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

// 2) Remove them
let results = await this._tokenCache.findThenable(query);
this._tokenCache.removeThenable(results);
getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Thenable<{}> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the type here be TokenResponse (and really should be TokenResponse | undefined given what _getSecurityToken can actually return)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah technically this is only called as an interface method defined

getSecurityToken(account: Account, resource: AzureResource): Thenable<{}>;

But yeah since that accepts any object I'll do that and actually update the azdata definition as well.

let self = this;
if (this.authMappings.size === 0) {
const msg = localize('azure.NoAuthMethod', "No Azure auth method selected");
console.log('noAuthMethodSelected');
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to log this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just so when we get bug reports in the future, more logs isn't a problem potentially?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess - should probably consider logging to a separate stream though if we care about that so we don't have to pick through console logging. Anyways fine with it either way - although I'd prefer you make the output more descriptive since someone seeing this in the logs would have absolutely no idea what this is referring to unless they knew the code.


In reply to: 395911374 [](ancestors = 395911374)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, i'll update the message.

If it helps this is a serious edgecase if you have multiple auth methods enabled. (Default will just be one)

};
});
});
const pick = await vscode.window.showQuickPick(options, { canPickMany: false });
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle user cancelling out of this correctly

Copy link
Contributor

@Charles-Gagnon Charles-Gagnon left a comment

Choose a reason for hiding this comment

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

Some smaller stuff but didn't see anything hugely stand out. I didn't really delve deep into the logic though since it gets pretty complex - I think we're just going to have to make sure to do thorough testing on it manually.

protected readonly memdb = new MemoryDatabase();

protected readonly WorkSchoolAccountType: string = 'work_school';
protected readonly MicrosoftAccountType: string = 'microsoft';
Copy link
Contributor

Choose a reason for hiding this comment

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

These feel like they should be defined in a more central location (or at least as const values somewhere)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm not really sure where though

src/sql/azdata.d.ts Show resolved Hide resolved
@@ -199,12 +230,16 @@
"@azure/arm-subscriptions": "1.0.0",
"adal-node": "^0.2.1",
"axios": "^0.19.2",
"keytar": "^5.4.0",
"qs": "^6.9.1",
Copy link
Member

Choose a reason for hiding this comment

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

we should update the 3rd-party notices when adding new runtime NPM modules.


function getSystemKeytar(): Keytar | undefined {
try {
return require('keytar');
Copy link
Member

Choose a reason for hiding this comment

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

what do we do on Linux systems that don't have an installed key manager?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'll fallback to encrypted file based storage.

@aaomidi aaomidi merged commit c15ac47 into master Mar 23, 2020
@aaomidi aaomidi deleted the amir/azureAuth/newProvider branch March 23, 2020 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants