I am using the Msal Guard in my Angular application.
I also have localization in my project.
I know that I can use the extraQueryParameters { ui_locales: 'de' }
in my RedirectRequest
object which I can then pass to the msalAuthService.loginRedirect
method.
But the msalGuard automatically does the login redirect when the user tries to navigate to a protected page. I wonder is there a way to pass the ui_locales to the msalGuard somehow? Or do I need to write my own custom guard to do this.
My solution was to write my own custom guard copying the code for the guard from github from Microsoft: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-angular/src/msal.guard.ts
Then I adapted the class which I copied, first by injecting the language, I have language service for this:
Then I had to change the method loginInteractively to pass the current language as the ui-locales property. This is the line I added:
extraQueryParameters: { ui_locales: this.currentLanguage },
And the whole method is shown below:Then I used this new MsalLocaleGuard in the providers section of my app.module.
This is not an optimal solution, because when Microsoft update the code in their guard, then the code in my guard which copied from github becomes outdated. But it is a workaround which suffices until there is a better way.