Skip to content

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

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

Closed

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>;

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Feb 3, 2025
@bradkovach
Copy link
Author

bump; still an issue in latest versions

@jo-arroyo @peterzenz @tnorling let me know if anything else can be done to move this DX fix along.

tnorling and others added 3 commits March 14, 2025 15:23
…AD#7623)

Splits up /authorize request generation into separate functions for 
1. Standard params (included on all requests)
2. Browser auth code params 
3. Node auth code params

Note: AzureAD#7633 adds another for Browser EAR
Note2: Future (uncommitted) work to move /token and /logout to a similar
pattern for extensibility and bundle size improvements
We encode all parameters added to the request URI, however, with the
introduction of EAR this will cause problems as the request parameters
are sent over form post, not QS. This PR moves the encode step to happen
during QS generation instead of during parameter addition to support
both use cases.
* Fix Date when expires_in as a string (will be fixed in MacOS in the
next iteration)
* Ignore userSwitch for double brokering (Brokers will help fixing this
long term)
@shylasummers
Copy link
Contributor

Thank you! As this is a breaking change, it will be included in the next major release of MSAL Angular. See #7651

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs: Attention 👋 Awaiting response from the MSAL.js team label Mar 19, 2025
@bradkovach
Copy link
Author

@shylasummers why are you closing my PR, re-implementing my work verbatim, and attributing this to yourself?

@shylasummers
Copy link
Contributor

@bradkovach If you would like this PR specifically merged, you would need to change the changefile to be a major version type (since this is a breaking change) and change the branch to merge into msal-v5

@shylasummers shylasummers reopened this Mar 19, 2025
@bradkovach bradkovach changed the base branch from dev to msal-v5 March 19, 2025 22:03
@github-actions github-actions bot added documentation Related to documentation. msal-node Related to msal-node package msal-browser Related to msal-browser package msal-common Related to msal-common package labels Mar 19, 2025
@bradkovach
Copy link
Author

This is done @shylasummers

The branches for dev and msal-v5 have diverged. Is dev regularly merged into v5?

If these need to be isolated from other commits in the graph, i can make a branch from v5 and cherry pick

@bradkovach
Copy link
Author

@shylasummers are you able to perform the proper git steps to merge this, or should i make a new branch and another PR?

@bradkovach
Copy link
Author

Closing in favor of #7653, which is using a different branch (based off of msal-v5 instead of dev)

@bradkovach bradkovach closed this Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Related to documentation. msal-angular Related to @azure/msal-angular package msal-browser Related to msal-browser package msal-common Related to msal-common package msal-node Related to msal-node package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants