Azure B2C session timeout

Ujwal Potluri 0 Reputation points
2025-02-27T14:48:37.9933333+00:00

We have a requirement to limit the Azure B2C session to 15 minutes so I put in the following snippet in our custom policy. This is for a sign in policy. After the user signs in by entering email and password, we have a MFA step. When I leave the page over there for 2 hours and come back, the session didn't timeout and I was able to move forward in the policy by entering the MFA code and log into the app. I tried different options of scope and expiry type but none of them seems to be working. I would really appreciate if someone can help me with this.

<SingleSignOn Scope="Application" />
<SessionExpiryType>Absolute</SessionExpiryType>
<SessionExpiryInSeconds>900</SessionExpiryInSeconds>
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
23,838 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sakshi Devkante 2,040 Reputation points Microsoft External Staff
    2025-02-27T17:25:43.0766667+00:00

    Hello Ujwal,

    Thank you for posting your query on Microsoft Q&A.

    I understand that you would like to have the browser cookies session expire after 15 minutes of inactivity.

    Please note that cookies session timeout is controlled by features in Azure B2C; KeepAliveInDays and SessionExpiryInSeconds. Once the KeepAliveInDays isn't enabled, then the SessionExpiryInSeconds handles the session timeout which is the case here.

    However, I noticed that you set the SessionExpiryType to Rolling which indicates that the session is extended every time the user performs a cookie-based authentication. This is the default behavior.

    To resolve this, kindly change the SessionExpiryType to Absolute which indicates that the user is forced to reauthenticate after the period specified. Also, make sure you aren’t passing the parameter prompt=login to AAD B2C.

    User's image

    Follow this link (https://learn.microsoft.com/en-us/azure/active-directory-b2c/session-behavior?pivots=b2c-custom-policy#configure-azure-ad-b2c-session-behavior) to learn more about information about Azure AD B2C Session behavior.

    Ensure that these settings are placed in the correct location within your policy. Typically, session expiry settings should be within the OrchestrationStep that handles the sign-in and the MFA part. If it’s placed in the wrong part of the policy, it might not be applied where expected.

    So, the solution is to look at the token lifetime behavior.

    The default is 60 minutes (1 hour). The minimum (inclusive) is 5 minutes. The maximum (inclusive) is 1,440 minutes (24 hours).

    So kindly set your token lifetime to 15 mins. This should be Access and ID token lifetimes

    Follow this link https://learn.microsoft.com/en-us/azure/active-directory-b2c/configure-tokens?pivots=b2c-custom-policy to get more information about this.

    You can configure the Azure AD B2C session behavior, including:

    Web app session lifetime (minutes) - The amount of time the Azure AD B2C session cookie is stored on the user's browser after successful authentication. You can set the session lifetime up to 24 hours.

    Web app session timeout - Indicates how a session is extended by the session lifetime setting or the Keep me signed in (KMSI) setting. Rolling - Indicates that the session is extended every time the user performs a cookie-based authentication (default). Absolute - Indicates that the user is forced to re-authenticate after the time period specified.

    User's image

    For more details you can refer this QnA post on same issue:
    1.https://learn.microsoft.com/en-us/answers/questions/1347290/understanding-b2c-web-app-session-timeout
    2. https://learn.microsoft.com/en-us/answers/questions/1103098/azure-ad-b2c-custom-policy-saml-token-lifetime-ses

    Documents: https://learn.microsoft.com/en-us/azure/active-directory/develop/refresh-tokens#token-timeouts.
    More info https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/token-lifetimes.md#token-lifetimes-expiration-and-renewal
    https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/4056#issuecomment-917246299

    I hope this clarifies things.


Your answer

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