Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure B2C Custom Policy read username by looking up the user with an extension attribute

I made the lookup work with querying with an extension attribute (in my case it is the special email we store for MFA purposes extension_mfaEmail)

Some users use username as main identity some use email.

I want to get the username as an output claim. After calling the technical profile: AAD-UserReadUsingMFAEmailAddress, the signinName claim returns the internal user principal name: {guid}@{tenant}.onmicrosoft.com which is not what I am looking for. I need the actual username that the user signs in with.

How do I know which method user uses? (email vs username) and regardless of this how can I read the username? Email is easier to work with but could not find a way for username

SigninNames.username is not recognized in this technical profile. Why?

   <TechnicalProfile Id="AAD-UserReadUsingMFAEmailAddress">

      <Metadata>

        <Item Key="Operation">Read</Item>

        <Item Key="RaiseErrorIfClaimsPrincipalDoesNotExist">true</Item>

      </Metadata>

      <IncludeInSso>false</IncludeInSso>

      <InputClaims>

        <InputClaim ClaimTypeReferenceId="email" PartnerClaimType="extension_mfaEmail"  />

      </InputClaims>

      <OutputClaims>

        <!-- Required claims -->

        <OutputClaim ClaimTypeReferenceId="objectId" />

        <OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="localAccountAuthentication" />

        <OutputClaim ClaimTypeReferenceId="userPrincipalName" />

        <OutputClaim ClaimTypeReferenceId="signInNames.emailAddress" />
      
        <OutputClaim ClaimTypeReferenceId="signInName" />

        <!-- HOW DO I READ USERNAME -->
       

      </OutputClaims>

      <OutputClaimsTransformations>
        <OutputClaimsTransformation ReferenceId="AssertAccountEnabledIsTrue" />
      </OutputClaimsTransformations>

      <IncludeTechnicalProfile ReferenceId="AAD-Common" />

    </TechnicalProfile>
like image 425
Erkan Y. Avatar asked Oct 26 '25 06:10

Erkan Y.


1 Answers

Adding below as output claim worked for me (displayUsername is just a simple readonly string claim that I added to my custom policy)

<OutputClaim ClaimTypeReferenceId="displayUserName" PartnerClaimType="signinNames.username" />
like image 140
Erkan Y. Avatar answered Oct 29 '25 07:10

Erkan Y.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!