Azure B2C: User not logged out after logoutURI

Hannes Dendoncker 20 Reputation points
2024-11-29T09:53:38.1933333+00:00

Hi,

I've configured a B2C tenant and built a .NET MVC app to use it as a login. Now, I'm trying add an option for the user to sign out, so a different account can be selected. Signing out of the app is easy, I just do

await HttpContext.SignOutAsync("Cookies");
await HttpContext.SignOutAsync("OpenIDConnect");  

but the issue is, when I log back in, I never get prompted to select an account, it defaults to the previous account, that still logged in with the B2C tenant. So next step, also log out of the B2C when the logout is called. I tried to do this by calling

logoutUrl = $"{azureAdB2COptions["Instance"]}{azureAdB2COptions["Domain"]}/b2c_1a_signup_signin/oauth2/v2.0/logout?" + $"post_logout_redirect_uri={Uri.EscapeDataString("https://localhost:7043/")}";

This runs fine, no errors, but the issue I had still persists! The user never gets logged out! This conflicts with all the information I find online. Any idea what causes this, the user is never logged out of the B2C tenant, or is instantly logged back in. I added this in my Program.cs

options.Prompt = "select_account";

but no luck. Any help is appreciated. Thank you.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Developer technologies | .NET | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 30,296 Reputation points Microsoft Employee Moderator
    2024-12-05T05:15:53.05+00:00

    Hi @Hannes Dendoncker

    Thank you for your patience.

    end_session_endpoint is used by the app to go to the logout page of B2C.

    Did you try to send a sign-out request directly:

    GET https://{tenant}.b2clogin.com/{tenant}.onmicrosoft.com/{policy}/oauth2/v2.0/logout?post_logout_redirect_uri=https%3A%2F%2Fjwt.ms%2F

    Also, as FrankEscarosBuechsel-MSFT mentioned, you need to configure session behavior in your custom policy.

    Could you please verify that KMSI(Keep me Signed In) is not enable in your application.

    <ClaimsProvider>
      <DisplayName>Local Account</DisplayName>
      <TechnicalProfiles>
        <TechnicalProfile Id="SelfAsserted-LocalAccountSignin-Email">
          <Metadata>
            <Item Key="setting.enableRememberMe">False</Item>      
         </Metadata>     
    </TechnicalProfile>
      </TechnicalProfiles>
    </ClaimsProvider>
    
    

    Also, while configuring the web app session timeout in your custom policy, configure it as :

    • Absolute - Indicates that the user is forced to reauthenticate after the time period specified.
    <UserJourneyBehaviors>
      <SingleSignOn Scope="Application" />
      <SessionExpiryType>Absolute</SessionExpiryType>
      <SessionExpiryInSeconds>86400</SessionExpiryInSeconds>
    </UserJourneyBehaviors>
    
    
    

    Hope this will help to validate the configuration at your end. If you are still facing issues, an idea would be to redirect using &prompt=login in your auth url will revoke your login request.

    Hope this will help.

    Thanks,

    Shweta


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.