-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Can't Use Custom App Initializer with HttpClient #3714
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
Comments
I am having the same issue. When removing this line, the wait for the I am able to fix this by fetching the relevant config in the main.ts file, providing it via an Injection Token and injecting the token back in the relevant service where you need the config.
our service |
Interesting @nicolaszawada. I don't have |
@brandonsmith86 to successfully initialize the application you will need to dynamically load the configuration as shown here using the fetch API to avoid the issue with circular dependency. |
@samuelkubai I'm not attempting to load dynamic msal configuration. I am attempting to use one of my own app initializers after MSAL has initialized. However, my initializer is executing before the MSAL initializers have finished. |
@brandonsmith86 Can you share your MSAL Angular configuration (specifically for teh guard and interceptor)? |
export function MSALInterceptorConfigFactory(): MsalInterceptorConfiguration {
return {
interactionType: InteractionType.Redirect,
protectedResourceMap: ResourceSettings.protectedResourceMap
};
}
export function MSALGuardConfigFactory(): MsalGuardConfiguration {
return {
interactionType: InteractionType.Redirect,
authRequest: {
scopes: OAuthSettings.scopes
}
};
} |
@brandonsmith86 Thanks. Applications using redirect-based navigation need to invoke |
@jasonnutter Isn't that the same as #2 in my description? In the provider, I am waiting for interaction to be set to none. However, it never happens. I can only assume it is because the app has to finish initializing. useFactory(appInitializer: UserService, msalBroadcast: MsalBroadcastService) {
return (
function(): Promise<User> {
return new Promise<User>(resolve => {
msalBroadcast.inProgress$
.pipe(filter((status: InteractionStatus) => status === InteractionStatus.None))
.subscribe(() => {
console.log("Done waiting to initialize UserService");
appInitializer.InitUserInfo().then(user => resolve(user));
});
});
}
);
} |
|
So you're saying I can |
I haven't had a chance to test this myself, but in theory, yes. Let us know if that doesn't work. |
@brandonsmith86 This issue has been automatically marked as stale because it is marked as requiring author feedback but has not had any activity for 5 days. If your issue has been resolved please let us know by closing the issue. If your issue has not been resolved please leave a comment to keep this open. It will be closed automatically in 7 days if it remains stale. |
Core Library
MSAL.js v2 (@azure/msal-browser)
Core Library Version
2.14.2
Wrapper Library
MSAL Angular (@azure/msal-angular)
Wrapper Library Version
2.0.0
Description
I am currently using msal-angular v2.0, and configuring everything via APP_INITIALIZER providers (including HTTP_INTERCEPTORS).
This all works great, until I try to add another APP_INITIALIZER that uses HttpClient (notice
UserServiceInitializer
in the previous code block). The purpose of this initializer is to get additional user info (by making an API call). The API call needs to have the access token included in the header (provided by MsalInterceptor). I have tried two different approaches (listed below), and both have failed. I would really appreciate any feedback that you can give.httpClient.get()
is called: "BrowserAuthError: interaction_in_progress: Interaction is currently in progress. Please ensure that this interaction has been completed before calling an interactive API."MSAL Configuration
Relevant Code Snippets
Identity Provider
Azure AD / MSA
Source
External (Customer)
The text was updated successfully, but these errors were encountered: