-
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
Angular 16: BrowserAuthError: uninitialized_public_client_application: You must call and await the initialize function before attempting to call any other MSAL API. #6693
Comments
Hey @Lakshman-Sundeep-Teki the error is pretty self-explanatory. The initialize method has to be the first step every time after creating a PCA instance. |
which means do i need to initialize the msal instance before redirection ? |
Yes, you need to call the initialize() method before making any token requests or redirection requests. Please take a look at our docs for more guidance! |
Hey @Lakshman-Sundeep-Teki are you bootstraping the MsalRedirectComponent or subscribing to handleRedirectObservable in your app.component.ts? Please double check with our migration doc. |
Hey @lalimasharda, Yes i'm bootstrapping the MsalRedirect component in
|
@lalimasharda , I tried like this but i am facing the issue called Since i'm using the RedirectComponent istead of
Error i am getting:
Could you please let me know what am i missing here :) |
I have the exact same problem. |
I am calling authService.initialize() (not awaited) in the constructor of the app.component.ts. It returns an Observable object and I wonder if there should be a callback function in subscribe, to handle what should happen when the initialization is done. |
Are you getting |
No. Here is my code (I modified it slightly).It is the ngOninit of app.component.ts:
|
Is it working as expected ? Let me try this :) |
@ludmillab , If i am doing like this i am getting error like below I am using msal redirection component in my application after modification my code in app.component.ts at ngOnInit
What am i missing here ? |
I'm not sure.
|
That would be:
|
Any progress on this cuase we need really to update to Angular 17 and it seems msal is causing the issue that its not compatible with esmodule? |
@muhamedkarajic, Not sure this is a correct way to implement like this. But i made a work around like the below :). Hope this help you
|
@Lakshman-Sundeep-Teki I would not recommend setting the 5 second timeout. Invoking |
Don't know we use Angular 17 and what I have for an issue is that its not building properly. I think this is required to be done to make the lib be on Angular 17. Sorry for misunderstanding. |
I solved with
in my service's constructor |
Core Library
MSAL.js (@azure/msal-browser)
Core Library Version
3.0.8
Wrapper Library
MSAL Angular (@azure/msal-angular)
Wrapper Library Version
None
Public or Confidential Client?
Public
Description
I am trying to authenticate user during the page load it self because, i want to authenticate user with out any button click. To achieve that i was trying to use loginRedirect in
onInit
life cycle hook of app.component.ts file, When i was trying to do like that i am facing an issueBrowserAuthError: uninitialized_public_client_application: You must call and await the initialize function before attempting to call any other MSAL API.
Is there any other way to authenticate user with out any button click
Error Message
BrowserAuthError: uninitialized_public_client_application: You must call and await the initialize function before attempting to call any other MSAL API. For more visit: aka.ms/msaljs/browser-errors
BrowserAuthError: uninitialized_public_client_application: You must call and await the initialize function before attempting to call any other MSAL API. For more visit: aka.ms/msaljs/browser-errors
Msal Logs
No response
MSAL Configuration
Relevant Code Snippets
Reproduction Steps
ng serve
in terminalExpected Behavior
Identity Provider
Azure AD / MSA
Browsers Affected (Select all that apply)
Chrome, Firefox, Edge
Regression
No response
Source
Internal (Microsoft)
The text was updated successfully, but these errors were encountered: