Search code examples
azuremicrosoft-graph-apiazure-ad-b2c

Microsoft Graph API ADB2C signInActivity update lag


We're trying to get the last sign-in time of some users of our ADB2C application. We've got the Microsoft Graph API query set up, and working - when we request https://graph.microsoft.com/v1.0/users?$select=signInActivity,displayName, mail, id,userPrincipalName, identities signInActivity is filled out.

The problem is that signInActivity takes a long time to update after a new sign-in. A test user signed in yesterday, around 20 hours ago, and their signInActivity.lastSignInDateTime hasn't been updated yet. We are sending the API request to check every hour.

Is there any way to force lastSignInDateTime to re-check the Azure sign-in logs and update them?


Solution

  • The signInActivity is coming from a different part of the tenant and not directly from the user object.

    It is my assumption that this is not updated in real time or run on overnight batch to save processing. I have no documentation to accommodate this assumption but it does align with things I've experienced before.

    If you need more up-to-date data the best approach is to save the sign-in date/time to the user object via an extension attribute.

    This wouldn't be supported with the built in user journeys, as the only API Connector that fires on each sign-in is the Before sending the token API Connector - although, you could call an API using this connector that updates the user object via Microsoft Graph... just note that you're adding more points of failure to the user's sign-in experience doing it this way.

    If you can move to B2C custom policies, you would need to add a custom attribute and update this during sign-in. There is something similar implemented in the Azure Sample - disable inactive account. You can see how the extension_lastLogonTime is implemented and updated on each sign-in.

    Note, even by updating the user object in Microsoft Graph or custom policies, there can still be up to 5 minute delay due to eventual consistency as the data replicates over the datacenters.


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.