ASP.NET Перенаправление UseOpenIdConnectAuthentication для выхода из системы после входа в систему

#c# #asp.net #.net

Вопрос:

У меня есть мозговой скребок.

В основном я настраиваю вход в Azure AD в нашем приложении .NET.

Мы перенаправляемся в MS для попытки входа в систему, он входит в систему нормально, мы находим пользователя в базе данных, но как только мы переходим к перенаправлению на главный экран входа в приложение, он возвращает нас непосредственно в Microsoft и просит выйти из системы.

Вот что мы делаем, чтобы соединить:

 app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
                app.UseCookieAuthentication(new CookieAuthenticationOptions
                {
                    AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
                    CookieName = "cookie",
                    ExpireTimeSpan = TimeSpan.FromHours(24),
                    CookieManager = new SystemWebChunkingCookieManager(),
                    Provider = new CookieAuthenticationProvider
                    {
                        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                            validateInterval: TimeSpan.FromMinutes(timeout),
                            regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                    }
                });

                app.UseOpenIdConnectAuthentication(
                    new OpenIdConnectAuthenticationOptions
                    {
                        // Sets the ClientId, authority, RedirectUri as obtained from web.config
                        AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
                        CookieManager = new SystemWebChunkingCookieManager(),
                        ClientId = singlsSignOnSettings.ClientId, //"c07475ff-c05d-4f5b-b67d-e831dcda479e",
                        Authority = "https://login.microsoftonline.com/"   singlsSignOnSettings.Authority   ".onmicrosoft.com",
                        RedirectUri = singlsSignOnSettings.RedirectUri,
                        // PostLogoutRedirectUri is the page that users will be redirected to after sign-out. In this case, it is using the home page
                        PostLogoutRedirectUri = singlsSignOnSettings.PostLogoutUri,
                        Scope = OpenIdConnectScope.OpenIdProfile,
                        // ResponseType is set to request the code id_token - which contains basic information about the signed-in user
                        ResponseType = OpenIdConnectResponseType.CodeIdToken,
                        // OpenIdConnectAuthenticationNotifications configures OWIN to send notification of failed authentications to OnAuthenticationFailed method
                        Notifications = new OpenIdConnectAuthenticationNotifications
                        {
                            AuthenticationFailed = OnAuthenticationFailed
                        },
                    });
 

В конце этого кода мы перенаправляемся на страницу выхода из системы MS.

             var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
            var signInManager = Context.GetOwinContext().Get<ApplicationSignInManager>();
            var loginInfo = Context.GetOwinContext().Authentication.GetExternalLoginInfo();
            if (loginInfo == null)
            {
                RedirectOnFail();
                return;
            }
            var user = manager.Find(loginInfo.Login);
            if (user != null)
            {
                signInManager.SignIn(user, isPersistent: false, rememberBrowser: false);
                IdentityHelper.RedirectToReturnUrl("/Secure/Main?id="   user.Id, Response);
            }
 

Кажется, я не могу найти причину для этого, но я понимаю, что, может быть, файл cookie удаляется?

Любая помощь была бы очень признательна.