Невозможно заставить «prompt=login» работать после обновления до логики Startup.csC#

Место общения программистов C#
Ответить
Anonymous
 Невозможно заставить «prompt=login» работать после обновления до логики Startup.cs

Сообщение Anonymous »

В рамках обновления приложения мне нужно было сделать несколько обновлений (Dot.Net 4.5 > 4.8, Owin и OpenIDConnect. Я не очень знаком с этой частью приложения, поэтому приведенные ниже изменения кода были предоставлены мне и Кажется, все работало нормально, за исключением одной проблемы: предыдущее поведение при входе и выходе из системы имело серьезную проблему: процессы входа и выхода из системы ведут себя неправильно.
Вот важная часть устаревшего запуска. cs:

Код: Выделить всё

    public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
CookieManager = new SystemWebCookieManager(),
CookieHttpOnly = true,
CookieSecure = CookieSecureOption.Always,
ExpireTimeSpan = TimeSpan.FromSeconds(Convert.ToInt32(_authSessionTimeout)),
SlidingExpiration = true
});

app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
// Sets the ClientId, authority, RedirectUri as obtained from web.config
ClientId = _clientId,
Authority = _authority,
RedirectUri = _redirectUri,
ClientSecret = _clientSecret,

// Do not use the token lifetime; this setting overrides the expiration of the auth cookie.
UseTokenLifetime = false,

// PostLogoutRedirectUri is the page that users will be redirected to after sign-out. In this case, it is using the home page
PostLogoutRedirectUri = _postLogoutRedirectUri,
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,
RedirectToIdentityProvider = ctx =>
{
// Prompt the user to login each time
ctx.ProtocolMessage.Prompt = "login";

// force re-authentication if the user hasn't logged in the last 15 minutes
ctx.ProtocolMessage.MaxAge = _authSessionTimeout;

return Task.FromResult(0);
}
}
}
);
}
а вот соответствующая часть нового start.auth.cs:

Код: Выделить всё

    public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
CookieManager = new SystemWebCookieManager(),
CookieHttpOnly = true,
CookieSecure = CookieSecureOption.Always,
ExpireTimeSpan = TimeSpan.FromSeconds(Convert.ToInt32(_authSessionTimeout)),
SlidingExpiration = true
});

app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
// Sets the ClientId, authority, RedirectUri as obtained from web.config
ClientId = _clientId,
Authority = _authority,
RedirectUri = _redirectUri,
ClientSecret = _clientSecret,

// Do not use the token lifetime; this setting overrides the expiration of the auth cookie.
UseTokenLifetime = false,

// PostLogoutRedirectUri is the page that users will be redirected to after sign-out.  In this case, it is using the home page
PostLogoutRedirectUri = _postLogoutRedirectUri,
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,
RedirectToIdentityProvider = ctx =>
{
// Prompt the user to login each time
ctx.ProtocolMessage.Prompt = "login";

// force re-authentication if the user hasn't logged in the last 15 minutes
ctx.ProtocolMessage.MaxAge = _authSessionTimeout;

return Task.FromResult(0);
}
}
}
);
}
Основная проблема здесь заключается в том, что при входе в систему СТАРЫЙ код включает в себя такие вещи, как 'Prompt="login"', а запрос NEW не так, как показано здесь:
Изображение

Честно говоря, я я совершенно потерялся в том, что кажется проблемой с OpenIdConnectAuthenticationNotifications, но я не могу найти четких ответов на вопрос, что может быть неправильным. Любая помощь будет принята с благодарностью.

Подробнее здесь: https://stackoverflow.com/questions/791 ... p-cs-logic
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»