B2C custom policy retry step (for loop)?

Patrice Côté 186 Reputation points
2022-09-28T18:36:42.547+00:00

Is there any way to retry a step in case the result is not good? Like a "for loop"?

Our use case is that a user adds an email address in the UI, our backend adds it to our DB and to B2C via Graph API (new identity type emailAddress) and immidiately after, calls a custom policy with MSAL. In that policy, the first step is a Read operation getting the "signInNames.emailAddress" and objectId with the username (6 digit unique identifier added as identity "signInType": "userName"). the problem we have is it doesn't find the new email address already. If we wait a few secondes (like with a Thread.Sleep in backend for exemple) that works fine.

We also tried reading from Graph API in our backend after the email creation to make sure we can read it and it does. Maybe because it's the same connection used to create the new address? And even so, the policy still doesn't see it at first.

For infos, here's a user from Graph :

"identities": [  
        {  
            "signInType": "userName",  
            "issuer": "mytenant.onmicrosoft.com",  
            "issuerAssignedId": "151840"  
        },  
        {  
            "signInType": "userPrincipalName",  
            "issuer": "mytenant.onmicrosoft.com",  
            "issuerAssignedId": "******@mytenant.onmicrosoft.com"  
        }  
    ]  

After we add the email identity :

"identities": [
{
"signInType": "emailAddress",
"issuer": "kmytenant.onmicrosoft.com",
"issuerAssignedId": "blablabla@Karima ben .com"
},
{
"signInType": "userName",
"issuer": "mytenant.onmicrosoft.com",
"issuerAssignedId": "151840"
},
{
"signInType": "userPrincipalName",
"issuer": "mytenant.onmicrosoft.com",
"issuerAssignedId": "******@mytenant.onmicrosoft.com"
}
]

And the AAD-UserReadUsingIdentifier TP :

<TechnicalProfile Id="AAD-UserReadUsingIdentifier">  
          <Metadata>  
            <Item Key="Operation">Read</Item>  
            <Item Key="RaiseErrorIfClaimsPrincipalDoesNotExist">true</Item>  
          </Metadata>  
          <IncludeInSso>false</IncludeInSso>  
          <InputClaims>  
            <InputClaim ClaimTypeReferenceId="readOnlySignInName" PartnerClaimType="signInNames" Required="true" />  
          </InputClaims>  
          <OutputClaims>  
            <OutputClaim ClaimTypeReferenceId="objectId" />  
            <OutputClaim ClaimTypeReferenceId="signInNames.emailAddress" />  
            <OutputClaim ClaimTypeReferenceId="strongAuthenticationEmailAddress" />  
          </OutputClaims>  
          <IncludeTechnicalProfile ReferenceId="AAD-Common" />  
        </TechnicalProfile>  

readOnlySignInName is a claimed populated with the login_hint query param received from the UI that contains the username.

EDIT the problem is more that the AAD-UserReadUsingIdentifier technical profile doesn't retreive the signInNames.emailAddress but finds it a few seconds later. Some latency between the write with the Graph API call and the Read in the policy. What can cause this? Isolation? Load balancing?

Microsoft Security | Microsoft Entra | Microsoft Entra External ID
0 comments No comments

Answer accepted by question author
Shweta Mathur 29,946 Reputation points Microsoft Employee Moderator
2022-09-30T07:25:08.247+00:00

Hi @Patrice Côté ,

Thanks for reaching out.

Azure AD B2C (as well as Azure AD) is a globally distributed multi-tenant system. There are multiple data centers around the world, each with copies of the data; and in order to ensure that we give you the absolute best performance we may route different calls through different sources to different data centers.

My guess is that because you are using one tool to do the update, and another tool to do the read, you are seeing propagation delay between the actual source of authority for those two systems at the time of the call which can't be avoided.

So, implementing initial wait and back-off will help in such scenarios.

Hope this will help.

Thanks,
Shweta

----------------------------------

Please remember to "Accept Answer" if answer helped you.

Was this answer helpful?


0 additional answers

Sort by: Oldest

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.