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

[Identity] Reverting ClientSecretCredential and UsernamePasswordCredential to v1 only for browsers, and fixing Karma browser bundles #14910

Merged
9 commits merged into from
Apr 17, 2021

Conversation

sadasant
Copy link
Contributor

@sadasant sadasant commented Apr 16, 2021

This PR makes it so ClientSecretCredential behaves like how it did on v1 only for browsers. It also ensures browser bundles can be used when built with Karma.


ClientSecretCredential (and also UsernamePasswordCredential)

Since the inception of Identity, we've been relying on ClientSecretCredential to be available in browsers to make it easier for us to automate bowser tests.

Whether ClientSecretCredential should continue being available on browsers in the future, is something yet to be decided. We started a conversation on the matter here: #14879

Our current plan is to switch master back to v1, as you can see here: #14909

Since the v2 changes to ClientSecretCredential won't be reverted, that means that as soon as we move master back to v1, all of our current clients will immediately start working with the latest ClientSecretCredential.

ClientSecretCredential was rewritten to use MSAL, specifically @azure/msal-node, which is not intended to work on browsers.

This PR makes it so ClientSecretCredential is kept as it was on v1 only for browsers. This will:

  • Allow us to keep our current browser recordings.
  • Allow us to continue using this credential for browser tests.
  • On v1, dropping this credential on browsers would be a breaking change, so this technically reduces the differences with v1.

Important:
Keep in mind that while we've always supported this credential in browsers, it can only work if browser security is disabled. This isn't recommended outside of our tests, and it's not something we should be advertising.

(Later we also did the same to UsernamePasswordCredential).


Browser bundles

While my initial change was scoped to one credential, I asked Harsha to test this PR and he found that the browser bundles would not work with Identity v2. We decided to fix it right away since this PR wouldn't be very useful with broken browser bundles.

@sadasant sadasant self-assigned this Apr 16, 2021
@ghost ghost added the Azure.Identity label Apr 16, 2021
@sadasant sadasant changed the title [Identity] Reverting client-secret to v1 in the browser only [Identity] Reverting ClientSecretCredential to v1 in the browser only Apr 16, 2021
@sadasant sadasant changed the title [Identity] Reverting ClientSecretCredential to v1 in the browser only [Identity] Reverting ClientSecretCredential to v1 only for browsers Apr 16, 2021
ramya-rao-a
ramya-rao-a previously approved these changes Apr 16, 2021
Copy link
Contributor

@ramya-rao-a ramya-rao-a left a comment

Choose a reason for hiding this comment

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

Thanks for the detailed PR description @sadasant
This makes sense to me

Reviewed that the file added for ClientSecretCredential for browser has the exact same code as what we had for this credential in v1

@HarshaNalluru
Copy link
Member

There are a couple other node-related things present in the browser bundle, we are working on removing them.

Copy link
Member

@HarshaNalluru HarshaNalluru left a comment

Choose a reason for hiding this comment

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

Waiting until we resolve all the errors with browser bundles.

@HarshaNalluru
Copy link
Member

HarshaNalluru commented Apr 16, 2021

While investigating with @sadasant...
I had to do b2ad072 on top of this PR to get identity v2 working with keyvault-secrets and keyvault-keys browser tests.

@ramya-rao-a ramya-rao-a dismissed their stale review April 16, 2021 22:40

Dismissing review as the scope of the PR has changed

@sadasant sadasant changed the title [Identity] Reverting ClientSecretCredential to v1 only for browsers [Identity] Reverting ClientSecretCredential to v1 only for browsers, and fixing Karma browser bundles Apr 16, 2021
@sadasant sadasant requested a review from ramya-rao-a April 16, 2021 23:04
if (isNode) {
assert.equal(error.name, "CredentialUnavailableError");
} else {
assert.equal(error.name, "AuthenticationError");
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the same behavior in v1 also right?

Copy link
Contributor

Choose a reason for hiding this comment

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

i.e. the fact that error that user would get is different in node vs browser for the same test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

The link suggests that previously we had AuthenticationError thrown for node as well. The reason for difference in node?

Copy link
Contributor Author

@sadasant sadasant Apr 16, 2021

Choose a reason for hiding this comment

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

This test uses ClientSecretCredential, which now has two different implementations. In this case the Node one is correct (on Node) because the provided tenant is not a valid tenant, so this credential can't be used. MSAL does validations like this that we don't do in v1.

@@ -2,6 +2,7 @@

## 2.0.0-beta.3 (Unreleased)

- Breaking change: Disabled `UsernamePasswordCredential` in browser bundles. This credential was never supported in browsers, but now that it uses MSAL, having it in browsers would break the browser bundles.
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the exact behavior in v1 when someone used UsernamePasswordCredential in the browser?

Copy link
Contributor Author

@sadasant sadasant Apr 16, 2021

Choose a reason for hiding this comment

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

It would work if CORS was disabled too: https://github.com/Azure/azure-sdk-for-js/blob/hotfix/identity_1.3.0/sdk/identity/identity/src/credentials/usernamePasswordCredential.ts should I bring this credential back as well? (only for the browser, of course)

Copy link
Contributor

Choose a reason for hiding this comment

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

If we are making ClientSecretCredential behavior in browser to be the same as in v1, shouldnt the same be applied to other credentials (other than of course InteractiveBrowserCredential)?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can touch the other credentials in a different PR, but since UsernamePasswordCredential is anyway being touched here, we should consider making the browser experience to be same as v1

Copy link
Contributor Author

@sadasant sadasant Apr 16, 2021

Choose a reason for hiding this comment

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

I can add UsernamePasswordCredential too. I feel like we should drop the ones we're not using to test stuff, but adding it would align us a little better with v1, so... I'll add it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed the v1 version of UsernamePasswordCredential on browsers 👍

@sadasant sadasant changed the title [Identity] Reverting ClientSecretCredential to v1 only for browsers, and fixing Karma browser bundles [Identity] Reverting ClientSecretCredential and UsernamePasswordCredential to v1 only for browsers, and fixing Karma browser bundles Apr 16, 2021
@ghost
Copy link

ghost commented Apr 17, 2021

Hello @sadasant!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 424ad49 into Azure:master Apr 17, 2021
@sadasant sadasant deleted the identity/clientSecretBrowserRevert branch April 17, 2021 14:35
jay-most pushed a commit to jay-most/azure-sdk-for-js that referenced this pull request Apr 26, 2021
…ntial to v1 only for browsers, and fixing Karma browser bundles (Azure#14910)

This PR makes it so `ClientSecretCredential` behaves like how it did on v1 only for browsers. It also ensures browser bundles can be used when built with Karma.

---

## ClientSecretCredential (and also UsernamePasswordCredential)

Since the inception of Identity, we've been relying on `ClientSecretCredential` to be available in browsers to make it easier for us to automate bowser tests.

Whether `ClientSecretCredential` should continue being available on browsers in the future, is something yet to be decided. We started a conversation on the matter here: Azure#14879 

Our current plan is to switch master back to v1, as you can see here: Azure#14909

Since the v2 changes to `ClientSecretCredential` won't be reverted, that means that as soon as we move master back to v1, all of our current clients will immediately start working with the latest `ClientSecretCredential`.

`ClientSecretCredential` was rewritten to use MSAL, specifically `@azure/msal-node`, which is not intended to work on browsers.

This PR makes it so `ClientSecretCredential` is kept as it was on v1 only for browsers. This will:

- Allow us to keep our current browser recordings.
- Allow us to continue using this credential for browser tests.
- On v1, dropping this credential on browsers would be a breaking change, so this technically reduces the differences with v1.

**Important:**
Keep in mind that while we've always supported this credential in browsers, it can only work if browser security is disabled. This isn't recommended outside of our tests, and it's not something we should be advertising.

(Later we also did the same to `UsernamePasswordCredential`).

---

## Browser bundles

While my initial change was scoped to one credential, I asked Harsha to test this PR and he found that the browser bundles would not work with Identity v2. We decided to fix it right away since this PR wouldn't be very useful with broken browser bundles.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants