-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
How to initialize msal configurations using APP_INITIALIZER #1403
Comments
@vinusorout Thanks, this information is really helpful! We'll make sure this gets documented. |
Thanks for example.
|
Hello, I have spent few days trying to make it work, but all the time msal config factory methods are invoked before the config file is recived. Where is the crucial part which wait until promise from config factory is returned? I am using Angular 9 and "@azure/msal-angular": "^1.0.0-beta.5"
msal-application.module.ts
|
This seems to be fine, please check all your dependencies, I think some other services or modules is initializing HttpClient before resolving appSettingsLoader. |
I'm also having trouble getting this to work. On my end it looks like the request is not even made. Instead the error handler of the subscribe call gets invoked with an error that happens when I try to access |
Alright, I found what was the problem that I had. I was injecting the HttpClient instead creating it with an injected backend like you do. After I changed that it started to work. |
As a confirmation I have removed MsalInterceptor from providers.
After that it start working. @vinusorout I will try to find where HttpClient is initialized.
|
You can create two modules Login n Home. Note: Use lazy loading for modules |
Thank you for suggestion, I handle it exactly the same as in settings loader, I have replace existing translation loader with my own.
|
Library
msal@1.x.x
or@azure/msal@1.x.x
@azure/msal-browser@2.x.x
@azure/msal-angular@0.x.x
@azure/msal-angular@1.x.x
@azure/msal-angularjs@1.x.x
Documentation location
Description
I found that most of the developers are facing issues in loading msal configurations from a config service/ app settings service, Even i struggled for couple of days. But finally I was able to achieve this.
Here is my solution:
config.service.ts:
Note config.service.ts, constructor, in this we are not injecting HttpClient, because if you inject HttpClient then angular first resolve all the HTTP_INTERCEPTORS, and when you use MsalInterceptor in app module, this makes angular to load MsalService and other component used by Msalinterceptor load before APP_INITIALIZER.
To resolve this issue we need to by pass HTTP_INTERCEPTORS, so for this we can use HttpBackend handler, and then create local instance of HttpClient in config service constructor.
This will bypass the HTTP_INTERCEPTORS, while getting config file.
msal-application.module.ts
Create a config.json file:
Now use this MsalApplicationModule in app.module.ts file, imports section as:
Now use MsalService in app.component.ts file as per the sample provided by the authors of this library.
The text was updated successfully, but these errors were encountered: