AzureAD / microsoft-authentication-library-for-js

Microsoft Authentication Library (MSAL) for JS
http://aka.ms/aadv2
MIT License
3.64k stars 2.65k forks source link

MSAL v2 to v3 migration | confusion about the initialization #7177

Closed zombaki closed 3 months ago

zombaki commented 3 months ago

Core Library

MSAL Node (@azure/msal-node)

Wrapper Library

MSAL Angular (@azure/msal-angular)

Public or Confidential Client?

Public

Documentation Location

https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/samples/msal-angular-v3-samples/angular16-sample-app/src/app/app.module.ts#L25

Description

In the documentation for migrating to version 2, we are instructed to create an instance of MSAL with two options: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/v2-migration.md#application-instantiation

However, in the MSAL Angular version 3 sample, this step is not performed: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/samples/msal-angular-v3-samples/angular16-sample-app/src/app/app.module.ts#L25

This discrepancy has led to confusion regarding whether the sample code is an accurate reference.

jo-arroyo commented 3 months ago

@zombaki The Angular 16 sample application creates a new instance of PublicClientApplication in the app.module.ts, as you linked above. For MSAL Angular v3, initialize is called in handleRedirectObservable in MsalService. As the sample application bootstraps the MsalRedirectComponent which subscribes to handleRedirectObservable, initialize is called when the application is run.

See the MSAL Angular upgrade guide for more details.

Closing with comment.