Выход из клиента не работает. Identity Server4

#reactjs #asp.net-core #identityserver4 #oidc-client-js

#reactjs #asp.net-core #identityserver4 #oidc-client-js

Вопрос:

В настоящее время я внедряю сервер OAuth с IdentityServer4, используя .NET Core 3.1 и React для клиентского SPA.

Когда я нажимаю выход из системы, я получаю следующее: введите описание изображения здесь

Реагировать JS:

    const handleLogout = async () => {
    const token = sessionStorage.getItem("id_token");
    userManager.signoutRedirect({
      id_token_hint: token
    });
   };
 

Конфигурация IdentityServer4:

    new Client
        {
            ClientId = _mobileAuthorizationCodeClientId,
            ClientName = _mobileAuthorizationCodeClientName,
            AllowedGrantTypes = GrantTypes.Code,
            RequirePkce = true,
            RequireClientSecret = false,
            RequireConsent = false,
            AllowAccessTokensViaBrowser = true,
            AllowOfflineAccess = true,
            
            AllowedScopes =
            {
                _avlApi, _clearingApi, _reportingApi, _assetManagementApi, _ticketingApi,
                IdentityServerConstants.StandardScopes.OpenId,
                IdentityServerConstants.StandardScopes.Profile,
                IdentityServerConstants.StandardScopes.OfflineAccess,
            },

            RedirectUris = { "https://localhost:3000/signin-callback" },
            PostLogoutRedirectUris = { "https://localhost:3000/signout-callback" },
            AllowedCorsOrigins = { "https://localhost:3000" },
        },
 

Соответствующие части Startup.cs:

         services.AddIdentity<ApplicationUser, IdentityRole>(config =>
        {
            config.Password.RequiredLength = 4;
            config.Password.RequireDigit = false;
            config.Password.RequireNonAlphanumeric = false;
            config.Password.RequireUppercase = false;
        })
        .AddEntityFrameworkStores<ApplicationDbContext>()
        .AddDefaultTokenProviders();

        services.AddIdentityServer(options =>
            {
                options.IssuerUri = publicOrigin;
                options.PublicOrigin = publicOrigin;
                options.UserInteraction = new UserInteractionOptions()
                {
                    LogoutUrl = "/account/logout",
                    LoginUrl = "/account/login",
                    LoginReturnUrlParameter = "returnUrl",
                    CustomRedirectReturnUrlParameter = "returnUrl",
                };
            })
            .AddAspNetIdentity<ApplicationUser>() 
            .AddInMemoryIdentityResources(Config.GetResources())
            .AddInMemoryApiResources(Config.GetApis())
            .AddInMemoryClients(Config.GetClients())
            .AddDeveloperSigningCredential()
            .AddProfileService<IdentityProfileService>();

        services.AddAuthentication();
 

Я не вижу никаких журналов ошибок от IDP.
Я пытался найти какое-то обходное решение подобной проблемы. https://github.com/IdentityServer/IdentityServer4/issues/3854

Странная вещь. Если подключение / завершение сеанса не отменено — выход из системы работает должным образом.

Мы используем https://github.com/maxmantz/redux-oidc для клиента react js.

Версии:

 <PackageReference Include="IdentityServer4" Version="3.1.3" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="3.1.3" />
 

Вопрос: почему connect / endsession отменяется?

Любая информация будет высоко оценена!

Ответ №1:

Вам не хватает ожидания в строке ниже?

ожидание UserManager.signoutRedirect({ id_token_hint: токен });

обычно запросы отменяются, когда пользователь перенаправляется на новую страницу, я вижу, что последующий вызов после отмены вызова — это авторизация, которая перенаправит пользователя…

надеюсь, добавление await может решить проблему.