SSO - How to logout?

SSO - How to logout?

I logged in using SSO and it worked.
But I want to use SSO to logout, and after checking, it seems that Session Endpoint is not supported.
I use the Revoke endpoint, but it automatically login after successfully revoke.
May I ask how to correctly exit SSO?


.Net 7 , OIDC
  1. authentication.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, "SSO", options =>
  2. {
  3.     options.ClientId = Configuration.GetValue<string>("SSO:ClientId");
  4.     options.ClientSecret = Configuration.GetValue<string>("SSO:ClientSecret");
  5.     options.MetadataAddress = Configuration.GetValue<string>("SSO:MetadataAddress");
  6.     options.ResponseType = OpenIdConnectResponseType.CodeIdTokenToken;
  7.     options.SaveTokens = true;
  8.     options.GetClaimsFromUserInfoEndpoint = true;
  9.     options.TokenValidationParameters.NameClaimType = "name";
  10.     options.TokenValidationParameters.RoleClaimType = "role";
  11. });


logout code
  1. protected override void OnLoggedOff()
  2. {
  3.     base.OnLoggedOff();
  4.     if (IsLoggedOn)
  5.     {
  6.         HttpContext httpContext = ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
  7.         if (httpContext != null)
  8.         {
  9.             var id_token = httpContext.GetTokenAsync("id_token").GetAwaiter().GetResult() ?? string.Empty;
  10.             var refresh_token = httpContext.GetTokenAsync("refresh_token").GetAwaiter().GetResult() ?? string.Empty;
  11.             var access_token = httpContext.GetTokenAsync("access_token").GetAwaiter().GetResult() ?? string.Empty;

  12.             var httpClientFactory = ServiceProvider.GetRequiredService<IHttpClientFactory>();
  13.             var httpClient = httpClientFactory.CreateClient();

  14.             using var request = new TokenRevocationRequest();
  15.             request.Address = Configuration.GetValue<string>("SSO:RevokeEndpoint");;
  16.             request.ClientId = Configuration.GetValue<string>("SSO:ClientId");
  17.             request.ClientSecret = Configuration.GetValue<string>("SSO:ClientSecret");

  18.             if (string.IsNullOrEmpty(access_token) == false)
  19.             {
  20.                 using TokenRevocationRequest request_AccessToken = request.Clone<TokenRevocationRequest>();
  21.                 request_AccessToken.Token = access_token;
  22.                 request_AccessToken.TokenTypeHint = "access_token";
  23.                 var response = httpClient.RevokeTokenAsync(request_AccessToken).GetAwaiter().GetResult();
  24.                 if (response.IsError)
  25.                 {

  26.                 }
  27.             }
  28.         }
  29.     }
  30. }


                New to ADManager Plus?

                  New to ADSelfService Plus?