Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit b909dfa

Browse files
committed
correctly read tpf from acr claim
1 parent 0cb0ef2 commit b909dfa

File tree

1 file changed

+9
-4
lines changed
  • 3-Authorization-II/2-call-api-b2c/SPA/src

1 file changed

+9
-4
lines changed

3-Authorization-II/2-call-api-b2c/SPA/src/App.jsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,22 @@ const Pages = () => {
3131
* policies may use "acr" instead of "tfp"). To learn more about B2C tokens, visit:
3232
* https://docs.microsoft.com/en-us/azure/active-directory-b2c/tokens-overview
3333
*/
34-
let tfp = event.payload.idTokenClaims['tfp'] ?? event.payload.idTokenClaims["acr"];
34+
let tfpClaim = event.payload.idTokenClaims['tfp'] ? 'tfp' : 'acr';
3535

36-
if (tfp=== b2cPolicies.names.editProfile) {
36+
function formatCase(policyName, tfpClaim) {
37+
// A custom policy's "acr" claim is returned in lowercase despite being expressed in uppercase in the Azure portal
38+
return tfpClaim === 'acr' ? policyName.toLowerCase(): policyName;
39+
}
40+
41+
if (event.payload.idTokenClaims[tfpClaim] === formatCase(b2cPolicies.names.editProfile, tfpClaim)) {
3742
// retrieve the account from initial sing-in to the app
3843
const originalSignInAccount = instance
3944
.getAllAccounts()
4045
.find(
4146
(account) =>
4247
account.idTokenClaims.oid === event.payload.idTokenClaims.oid &&
4348
account.idTokenClaims.sub === event.payload.idTokenClaims.sub &&
44-
account.idTokenClaims['tfp'] === b2cPolicies.names.signUpSignIn
49+
(account.idTokenClaims['tfp'] === b2cPolicies.names.signUpSignIn || account.idTokenClaims['acr'] === formatCase(b2cPolicies.names.signUpSignIn,'acr'))
4550
);
4651

4752
let signUpSignInFlowRequest = {
@@ -60,7 +65,7 @@ const Pages = () => {
6065
* you can replace the code below with the same pattern used for handling the return from
6166
* profile edit flow
6267
*/
63-
if (tfp === b2cPolicies.names.forgotPassword) {
68+
if (event.payload.idTokenClaims[tfpClaim] === formatCase(b2cPolicies.names.forgotPassword, tfpClaim)) {
6469
let signUpSignInFlowRequest = {
6570
authority: b2cPolicies.authorities.signUpSignIn.authority,
6671
scopes: [

0 commit comments

Comments
 (0)