我有配置這樣的OAuth登錄時的WebAPI:WebAPI OAuth註銷 - 如何刪除令牌Cookie?
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = "https://www.microsoft.com/",
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});
,並登錄使用
config.Filters.Add(new System.Web.Http.AuthorizeAttribute());
我現在想添加一個名爲LogoutController的ApiController(猜它做什麼)強制執行所有控制器。
I have found that I can logout from MVC使用
System.Web.Security.FormsAuthentication.SignOut();
但我不從的WebAPI註銷的方式。我還沒有找到任何信息如何從WebAPI註銷。但我發現,there may be a bug in logout procedure, the cookie is kept and has to be removed manually,但隨後,該代碼是MVC一遍,它好像我不能得到一個HttpCookie
進入我HttpResponseMessage
對象:我怎樣才能做到這一點我的WebAPI被註銷
[HttpGet]
public HttpResponseMessage Logout()
{
FormsAuthentication.SignOut();
// clear authentication cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent("<html><title>Logout successful</title><body style=\"font-family:sans-serif\"><div style=\"display:table; width:100%; height:100%; margin:0; padding:0; \"><div style=\"display:table-cell; vertical-align:middle; text-align:center;\">You have been successfully logged out.<br>You can close this window/tab now.</div></div></body></html>");
response.Headers.AddCookies(cookie1); // Types don't match
return response;
}
並且在我登錄之前需要再次完成OAuth?