LogoutPath 有什么作用吗?
Does LogoutPath do anything?
我正在编写示例应用程序。利用 OWIN 和 UseCookieAuthentication
。后者接受 CookieAuthenticationOptions
,它有一个 LogoutPath
属性。此 属性 具有以下相关注释:
If the LogoutPath is provided the middleware then a request to that path will redirect based on the ReturnUrlParameter.
但是,我无法弄清楚这是否会执行任何操作,或者它是否仅表示您的代码将执行某些操作的隐含合同。例如,如果我利用 AuthenticationManager.SignOut()
,我希望注销路径端点会被调用。
查看 Microsoft.Owin.Security
的反编译代码,如果指定了 LogOutPath,它会尝试执行重定向。它将重定向到查询字符串中的 returnUrl 参数。所以再总结一下。
If the current request matches your LogOutPath and it has a returnUrl parameter, the OWIN middleware will automatically redirect to the returnUrl specified in the query string. Otherwise it will do nothing.
有用的功能可能是,您注销并希望重定向回同一页面,该页面现在对匿名用户的功能已降级。
bool shouldLoginRedirect = num1 != 0;
int num2;
if (shouldSignout)
{
PathString logoutPath = this.get_Options().LogoutPath;
// ISSUE: explicit reference operation
if (((PathString) @logoutPath).get_HasValue())
{
num2 = PathString.op_Equality(((AuthenticationHandler) this).get_Request().get_Path(), this.get_Options().LogoutPath) ? 1 : 0;
goto label_22;
}
}
num2 = 0;
label_22:
bool shouldLogoutRedirect = num2 != 0;
if ((shouldLoginRedirect || shouldLogoutRedirect) && ((AuthenticationHandler) this).get_Response().get_StatusCode() == 200)
{
string str = ((AuthenticationHandler) this).get_Request().get_Query().Get(this.get_Options().ReturnUrlParameter);
if (!string.IsNullOrWhiteSpace(str) && CookieAuthenticationHandler.IsHostRelative(str))
this.get_Options().Provider.ApplyRedirect(new CookieApplyRedirectContext(((AuthenticationHandler) this).get_Context(), this.get_Options(), str));
}
}
感谢 Khalid Abuhakmeh 提供更多见解。但是,我的困惑最终是由于假设在指定 LogoutPath
属性 时映射了隐式端点。添加以下内容后,请求 /logout?ReturnUrl=/
按预期工作:
app.Map("/logout", logout =>
{
logout.Run(context =>
{
context.Authentication.SignOut();
return Task.FromResult(0);
});
});
没有显式地图,我得到 404。
作为附加说明,我还错误地假设向 SignOut
提供 AuthenticationProperties
-实例将允许我指定 return-url(而不是将其作为请求的一部分 url)。看来这只适用于 external cookie authentication.
我正在编写示例应用程序。利用 OWIN 和 UseCookieAuthentication
。后者接受 CookieAuthenticationOptions
,它有一个 LogoutPath
属性。此 属性 具有以下相关注释:
If the LogoutPath is provided the middleware then a request to that path will redirect based on the ReturnUrlParameter.
但是,我无法弄清楚这是否会执行任何操作,或者它是否仅表示您的代码将执行某些操作的隐含合同。例如,如果我利用 AuthenticationManager.SignOut()
,我希望注销路径端点会被调用。
查看 Microsoft.Owin.Security
的反编译代码,如果指定了 LogOutPath,它会尝试执行重定向。它将重定向到查询字符串中的 returnUrl 参数。所以再总结一下。
If the current request matches your LogOutPath and it has a returnUrl parameter, the OWIN middleware will automatically redirect to the returnUrl specified in the query string. Otherwise it will do nothing.
有用的功能可能是,您注销并希望重定向回同一页面,该页面现在对匿名用户的功能已降级。
bool shouldLoginRedirect = num1 != 0;
int num2;
if (shouldSignout)
{
PathString logoutPath = this.get_Options().LogoutPath;
// ISSUE: explicit reference operation
if (((PathString) @logoutPath).get_HasValue())
{
num2 = PathString.op_Equality(((AuthenticationHandler) this).get_Request().get_Path(), this.get_Options().LogoutPath) ? 1 : 0;
goto label_22;
}
}
num2 = 0;
label_22:
bool shouldLogoutRedirect = num2 != 0;
if ((shouldLoginRedirect || shouldLogoutRedirect) && ((AuthenticationHandler) this).get_Response().get_StatusCode() == 200)
{
string str = ((AuthenticationHandler) this).get_Request().get_Query().Get(this.get_Options().ReturnUrlParameter);
if (!string.IsNullOrWhiteSpace(str) && CookieAuthenticationHandler.IsHostRelative(str))
this.get_Options().Provider.ApplyRedirect(new CookieApplyRedirectContext(((AuthenticationHandler) this).get_Context(), this.get_Options(), str));
}
}
感谢 Khalid Abuhakmeh 提供更多见解。但是,我的困惑最终是由于假设在指定 LogoutPath
属性 时映射了隐式端点。添加以下内容后,请求 /logout?ReturnUrl=/
按预期工作:
app.Map("/logout", logout =>
{
logout.Run(context =>
{
context.Authentication.SignOut();
return Task.FromResult(0);
});
});
没有显式地图,我得到 404。
作为附加说明,我还错误地假设向 SignOut
提供 AuthenticationProperties
-实例将允许我指定 return-url(而不是将其作为请求的一部分 url)。看来这只适用于 external cookie authentication.