Skip to content

Dependency Update for Ch1 Vanilla JS#85

Merged
iambmelt merged 3 commits intoAzure-Samples:mainfrom
BenBagBag:vanilla-js-clean-signin
Jun 7, 2024
Merged

Dependency Update for Ch1 Vanilla JS#85
iambmelt merged 3 commits intoAzure-Samples:mainfrom
BenBagBag:vanilla-js-clean-signin

Conversation

@BenBagBag
Copy link
Copy Markdown
Contributor

@BenBagBag BenBagBag commented Jun 6, 2024

Purpose

  • Updates NPM packages to most recent versions
  • Fixes some bugs in the sample
  • Fixes tests

Does this introduce a breaking change?

[ ] Yes
[ x ] No

Pull Request Type

What kind of change does this Pull Request introduce?

[ x ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ x ] Other... Please describe: Dependency update

How to Test

  • Get the code
git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
npm install
  • Test the code
  • Add your app creds to authConfig.js
cd 1-Authentication\0-sign-in-vanillajs\App
npm start
  • Go to localhost:3000
  • Sign in, with an external ID
  • Test popup option by commenting out lines indicated in index.html and redirect.html
  • Run tests by deleting your creds in authConfig.js and then running jest test

What to Check

Verify that the following are valid

  • You can log in
  • You see a page verifying that you're logged in
  • You can log out
  • You can click a link in the logout page to get back to the signin/welcome page

Other Information

@BenBagBag BenBagBag changed the title history fix Dependency Update for Ch1 Vanilla JS Jun 6, 2024
@iambmelt iambmelt self-requested a review June 6, 2024 20:59
@iambmelt
Copy link
Copy Markdown
Contributor

iambmelt commented Jun 6, 2024

@BenBagBag - The diff for this PR is pretty noisy so I'm having trouble seeing where the differences are from main branch, are there specific sets of this change you want to call attention to for review?

@@ -10,13 +10,13 @@
"author": "",
"license": "ISC",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated dependencies.

authority: 'https://Enter_the_Tenant_Subdomain_Here.ciamlogin.com/', // Replace the placeholder with your tenant subdomain
redirectUri: '/', // You must register this URI on Azure Portal/App Registration. Defaults to window.location.href e.g. http://localhost:3000/
authority: 'https://Enter_the_Tenant_Subdomain_Here.ciamlogin.com/', // Replace the placeholder with your tenant subdomain
redirectUri: 'http://localhost:3000/redirect', // You must register this URI on Azure Portal/App Registration. Defaults to window.location.href e.g. http://localhost:3000/
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed the redirect URI so that the popup option works properly.

* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/request-response-object.md#request
*/
loginRequest.redirectUri = "/redirect";
myMSALObj.loginPopup(loginRequest)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a value to loginRequest or else this option gives a blank page after authing.

* response returned from redirect flow. For more information, visit:
* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/initialization.md#redirect-apis
*/
myMSALObj.handleRedirectPromise()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wrapped this in a promise to make sure it doesn't run before the myMSALObj is initialized.

<!-- uncomment the above line and comment the line below if you would like to use the redirect flow -->
<script type="text/javascript" src="./authRedirect.js"></script>
<!-- comment the above line and uncomment the line below if you would like to use the popup flow -->
<!-- <script type="text/javascript" src="./authPopup.js"></script> -->
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Made this a little clearer, as the tutorial assumes that redirect is your default, not popup.

https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/login-user.md#redirecturi-considerations
--> No newline at end of file
-->
<script src="/msal-browser.min.js"></script>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Without the script tags, the redirect page won't actually redirect.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The original intention for this page was for it to be used in the popup flow, where MSAL polls the URL from the main window. I think it'd be worth trying to just use /redirect as the redirectUri in the popup request and leave the redirect as localhost:3000 in the redirect request. This way you can remove these scripts from this page and leave it actually blank.

global.document.documentElement.innerHTML = html.toString();
});

it('should have valid cdn link', () => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tutorial doesn't actually use the CDN link option, so removed this test.

Also updated some file paths so that the tests pass.

@BenBagBag
Copy link
Copy Markdown
Contributor Author

@iambmelt Sorry, that's due to the Git issue I mentioned in Teams. I put in comments to show where the changes happened. Shouldn't happen in future commits.


// Choose which account to logout from by passing a username.
const logoutRequest = {
account: myMSALObj.getAccountByUsername(username),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you update this to use the new getAccount API, this is deprecated...

Suggested change
account: myMSALObj.getAccountByUsername(username),
account: myMSALObj.getAccount({ username: username }),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please make sure the change works ofc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated, please take another look.

https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/login-user.md#redirecturi-considerations
--> No newline at end of file
-->
<script src="/msal-browser.min.js"></script>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The original intention for this page was for it to be used in the popup flow, where MSAL polls the URL from the main window. I think it'd be worth trying to just use /redirect as the redirectUri in the popup request and leave the redirect as localhost:3000 in the redirect request. This way you can remove these scripts from this page and leave it actually blank.

Copy link
Copy Markdown
Contributor

@iambmelt iambmelt left a comment

Choose a reason for hiding this comment

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

signing off as well, thanks @BenBagBag

@BenBagBag
Copy link
Copy Markdown
Contributor Author

@iambmelt and @hectormmg I do not have merge permissions. :)

@iambmelt iambmelt merged commit 08a3ba5 into Azure-Samples:main Jun 7, 2024
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.

3 participants