Saml2: I got the logout event from the IDP, but which user has logged out?

483 views Asked by At

I am implementing a SP that allows users to log in using a SAML2 IDP. I am implementing the SP using ASP.NET Core and the Sustainsys Saml2 package. We are using the OWIN middleware. It works well to log in. I have added a certificate and the whole ting runs as an azure website. My issue is to detect which user has logged out if the IDP sends a logout event.

We get the SessionIndex and LogoutNameIdentifier when logging in, but not when logging out.

Using a SAML2 tracer in the browser I see that I receive a logout package from the IDP that looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<saml2p:LogoutRequest 
    xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" 
    Destination="https://example.com/Saml2/Logout" 
    ID="_0498f5109d6c09a3de3dc5a7ee6ef34bdd" 
    IssueInstant="2020-10-11T15:01:46.408Z" Version="2.0">
  <saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
       https://my.testidp.com/samlv2/idp/metadata/0/30
  </saml2:Issuer>
  <saml2:NameID 
       xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" 
       Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">
           _041d2ec8046088eed3567c8761a925b48e
  </saml2:NameID>
</saml2p:LogoutRequest>

In the Startup.cs I have added an event handler for the logout event named LogoutCommandResultCreated. It looks like this: (somewhat simplified)

    public void ConfigureServices(IServiceCollection services)
    {
            var authenticationBuilder = services.AddAuthentication(options =>
            {
                options.DefaultScheme = "Cookies";
                options.DefaultChallengeScheme = "oidc";
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;

            });
            authenticationBuilder.AddCookie("Cookies");
            string authenticationScheme = $"{configheader.Name}.saml2";
            authenticationBuilder.AddSaml2(authenticationScheme, options =>
            {
                ...

               var spOptions = new SPOptions
               {
                   EntityId = new EntityId(entityId),
                   Organization = myorganization,
                   MinIncomingSigningAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1",
                   ModulePath = "/Saml2",
                   ReturnUrl = new Uri("/auth/saml2/", UriKind.Relative)
               };

               spOptions.ServiceCertificates.Add(mycertificate);

               options.SPOptions = spOptions;
               options.Notifications.LogoutCommandResultCreated = commandResult =>
               {
                  // LOGOUT TRIGGERED.
                  logger.LogDebug(Newtonsoft.Json.JsonConvert.SerializeObject(commandResult));
                  // TODO: What to do with commandResult?
               };

The output of the json-serialization of the commandResult didn't give me much:

{"HttpStatusCode":303,
"Cacheability":1,
"Location":"https://my.testidp.com/samlv2/idp/sloresp/0/30?mgvhostparam=0
     &SAMLResponse=jJHLasMwEEX3hf6D0d6W%2FGws7JTSbAL....kd8%2BK%2Fh7%2B8gcAAP%2F%2FAwA%3D
     &igAlg=http%3A%2F%2Fwww.w3.org%2F2001%2F04%2Fxmldsig-more%23rsa-sha256 
     &Signature=nmZApcBYHbsnNruq...duQA%3D",
"Principal":null,
"SessionNotOnOrAfter":null,
"Content":null,"ContentType":null,
"RelayData":null,"TerminateLocalSession":true,
"SetCookieName":null,
"SetCookieSecureFlag":false,
"RelayState":null,
"RequestState":null,
"ClearCookieName":null,
"HandledResult":false,
"Headers":{}}
  • Is this the correct way to detect the logout event from the IDP?
  • How do I interpret the commandResult?
  • Most important, how do I find which user has been logged out from the IDP?
1

There are 1 answers

0
Bernhard Thalmayr On

As NameID format urn:oasis:names:tc:SAML:2.0:nameid-format:transient was used to perform SSO, you need to find the NameId value on SP end.