I want last_login log for a user inside the access token when we login to az ad b2c. Is that possible ?
Thanks
@amanpreetsingh-msft can you please help on this ?
I want last_login log for a user inside the access token when we login to az ad b2c. Is that possible ?
Thanks
@amanpreetsingh-msft can you please help on this ?
@AbhayChandramouli-2076 • Thank you for reaching out.
Azure AD B2C by default doesn't store the last login time of the users. However, you can create a custom claim that can capture the current date and time (during users' sign-in) and pass that in the access token issued after sign-in. You can then configure your application to read this claim and store it to keep track of the last time the user logged in. You can also write this value to the user's property in the B2C directory by persisting the claim but that would be a complicated task and would require a lot of testing as there is no sample currently available for this purpose.
For this purpose, you need to perform the below steps:
Create a custom claim:
<ClaimType Id="extension_LastLogin">
<DisplayName>extension_LastLogin</DisplayName>
<DataType>dateTime</DataType>
<UserInputType>Readonly</UserInputType>
</ClaimType>
Create a claims transformation rule:
<ClaimsTransformation Id="GetLastLoginDateTime" TransformationMethod="GetCurrentDateTime">
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="extension_LastLogin" TransformationClaimType="currentDateTime" />
</OutputClaims>
</ClaimsTransformation>
Update the login-NonInteractive technical profile.
<TechnicalProfile Id="login-NonInteractive">
...
<InputClaimsTransformations>
<InputClaimsTransformation ReferenceId="GetLastLoginDateTime" />
</InputClaimsTransformations>
<InputClaims>
<InputClaim ClaimTypeReferenceId="signInName" />
<InputClaim ClaimTypeReferenceId="extension_LastLogin" />
</InputClaims>
<OutputClaims>
...
<OutputClaim ClaimTypeReferenceId="extension_LastLogin" />
</OutputClaims>
Update the output claims of the SelfAsserted-LocalAccountSignin-Email technical profile.
<TechnicalProfile Id="SelfAsserted-LocalAccountSignin-Email">
...
<OutputClaims>
...
<OutputClaim ClaimTypeReferenceId="extension_LastLogin" />
</OutputClaims>
Update the output claims in the Signup/Sign-in XML file:
<OutputClaim ClaimTypeReferenceId="extension_LastLogin" PartnerClaimType="LastLogin" />
Note: If you are not using email-based sign-ins, you would need to update the relevant technical profile.
Please "Accept the answer" if the information helped you. This will help us and others in the community as well.
@AbhayChandramouli-2076 • Just checking if you have any further questions on this.
9 people are following this question.