Skip to content
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

Adjust InjectionToken<T> constants in msal-angular to support typed Angular 14+ inject() #7484

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

bradkovach
Copy link

This PR adjusts InjectionToken instantiation to use the proper template type parameter (instead of string), so that the new Angular 14+ inject(TOKEN) syntax can be used if desired.

import { MSAL_INSTANCE, MSAL_GUARD_CONFIG, MSAL_INTERCEPTOR_CONFIG, MSAL_BROADCAST_CONFIG
@Component({
   // ...
})
export class MyComponent {
   msalInstance = inject(MSAL_INSTANCE); // resolves to IPublicClientApplication
   msalGuardConfig = inject(MSAL_GUARD_CONFIG); // resolves to MsalGuardConfiguration
   msalInterceptorConfig = inject(MSAL_INTERCEPTOR_CONFIG); // resolves to MsalInterceptorConfiguration
   msalBroadcastConfig = inject(MSAL_BROADCAST_CONFIG); // resolves to MsalBroadcastConfiguration
}

@github-actions github-actions bot added the msal-angular Related to @azure/msal-angular package label Dec 30, 2024
@bradkovach
Copy link
Author

@microsoft-github-policy-service agree

@bradkovach
Copy link
Author

This is related to #7413, and fixes #6006

For anyone having issues with this, you can add some new constants to your own project to replace the existing broken ones.

export const TYPED_MSAL_INSTANCE =
  MSAL_INSTANCE as unknown as InjectionToken<IPublicClientApplication>;
export const TYPED_MSAL_GUARD_CONFIG =
  MSAL_GUARD_CONFIG as unknown as InjectionToken<MsalGuardConfiguration>;
export const TYPED_MSAL_INTERCEPTOR_CONFIG =
  MSAL_INTERCEPTOR_CONFIG as unknown as InjectionToken<MsalInterceptorConfiguration>;
export const TYPED_MSAL_BROADCAST_CONFIG =
  MSAL_BROADCAST_CONFIG as unknown as InjectionToken<MsalBroadcastConfiguration>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
msal-angular Related to @azure/msal-angular package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant