Пожалуйста, прости меня, если заранее, если я что-то пропустил или допустил ошибку. Я думаю, что мне нужно было публиковать здесь только пару раз ....
Я гуглил эту ситуацию в течение двух дней, пробуя то и это, и я не ближе к тому, чтобы решить это. Что-то в Chrome изменилось, и это сломало мое приложение. Сценарий таков: у меня есть приложение MVC 5, которое использует SSO. Первый вход в систему приводит меня на страницу входа в microsoftonline, и я могу войти в систему успешно, после чего я попадаю на страницу redirectURI моего приложения и Request.IsAuthenticated = true. Все хорошо. Однако, если я либо закрою браузер, либо воспользуюсь ссылкой «Выход из системы» (которая выполняет приведенный ниже код выхода из системы) и попытаюсь снова получить доступ к своему приложению, я попаду на страницу входа в microsoftonline, как и ожидалось, введите свой пароль, но во второй раз запрос. IsAuthenticated = false и мое приложение больше не работает. Он ожидает, что Request.IsAuthenticated будет истинным, и, поскольку он ложный, он снова перенаправляет на страницу входа в microsoftonline, что приводит к константе l oop. Я обнаружил, что могу перезапустить веб-сайт, и он каким-то образом сбрасывает Request.IsAuthenticated, чтобы я мог снова войти в систему.
У меня больше нет идей, как это исправить. Любая помощь очень ценится.
Вот SSOAuthConfig: (в основном это точная копия Azure Регистрация приложения ASP. Net Пример быстрого запуска)
internal static class SSOAuthConfig2020
{
// The Client ID is used by the application to uniquely identify itself to Azure AD.
static string clientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"];
// RedirectUri is the URL where the user will be redirected to after they sign in.
static string redirectUri = System.Configuration.ConfigurationManager.AppSettings["RedirectUri"];
// Tenant is the tenant ID (e.g. contoso.onmicrosoft.com, or 'common' for multi-tenant)
static string tenant = System.Configuration.ConfigurationManager.AppSettings["Tenant"];
// Authority is the URL for authority, composed by Microsoft identity platform endpoint and the tenant name (e.g. https://login.microsoftonline.com/contoso.onmicrosoft.com/v2.0)
static string authority = String.Format(System.Globalization.CultureInfo.InvariantCulture, System.Configuration.ConfigurationManager.AppSettings["Authority"], tenant);
/// <summary>
/// Configure OWIN to use OpenIdConnect
/// </summary>
/// <param name="app"></param>
public static void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
var cookieAuthenticationOptions = new CookieAuthenticationOptions()
{
CookieName = "MyFakeCookieName",
ExpireTimeSpan = TimeSpan.FromDays(1),
AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
SlidingExpiration = true,
};
app.UseCookieAuthentication(cookieAuthenticationOptions);
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
// Sets the ClientId, authority, RedirectUri as obtained from web.config
ClientId = clientId,
Authority = authority,
RedirectUri = redirectUri,
// PostLogoutRedirectUri is the page that users will be redirected to after sign-out. In this case, it is using the home page
PostLogoutRedirectUri = redirectUri,
Scope = OpenIdConnectScope.OpenIdProfile,
// ResponseType is set to request the id_token - which contains basic information about the signed-in user
ResponseType = OpenIdConnectResponseType.IdToken,
// ValidateIssuer set to false to allow personal and work accounts from any organization to sign in to your application
// To only allow users from a single organizations, set ValidateIssuer to true and 'tenant' setting in web.config to the tenant name
// To allow users from only a list of specific organizations, set ValidateIssuer to true and use ValidIssuers parameter
TokenValidationParameters = new TokenValidationParameters()
{
ValidateIssuer = true
},
// OpenIdConnectAuthenticationNotifications configures OWIN to send notification of failed authentications to OnAuthenticationFailed method
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = OnAuthenticationFailed,
AuthorizationCodeReceived = async n =>
{
n.AuthenticationTicket.Properties.ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(60);
n.AuthenticationTicket.Properties.IsPersistent = true;
n.AuthenticationTicket.Properties.AllowRefresh = true;
n.AuthenticationTicket.Properties.IssuedUtc = DateTimeOffset.UtcNow;
}
}
}
);
}
Вот логин логина c:
public void SignIn()
{
if (!Request.IsAuthenticated)
{
HttpContext.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "/Client" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
}
Вот логин:
public void SignOut()
{
try
{
HttpContext.GetOwinContext().Authentication.SignOut(
OpenIdConnectAuthenticationDefaults.AuthenticationType,
CookieAuthenticationDefaults.AuthenticationType);
}
catch (Exception ex)
{
}
}