/// <summary> /// Remove the Users Session /// </summary> /// <param name="service"></param> /// <param name="request"></param> /// <returns></returns> public virtual object Logout(IServiceBase service, Authenticate request) { var feature = HostContext.GetPlugin <AuthFeature>(); var session = service.GetSession(); var referrerUrl = service.Request.GetReturnUrl() ?? (feature.HtmlLogoutRedirect != null ? service.Request.ResolveAbsoluteUrl(feature.HtmlLogoutRedirect) : null) ?? session.ReferrerUrl ?? service.Request.GetHeader("Referer").NotLogoutUrl() ?? this.RedirectUrl; session.OnLogout(service); AuthEvents.OnLogout(service.Request, session, service); service.RemoveSession(); if (feature != null && feature.DeleteSessionCookiesOnLogout) { service.Request.Response.DeleteSessionCookies(); service.Request.Response.DeleteJwtCookie(); } if (service.Request.ResponseContentType == MimeTypes.Html && !string.IsNullOrEmpty(referrerUrl)) { return(service.Redirect(LogoutUrlFilter(this, referrerUrl))); } return(new AuthenticateResponse()); }
/// <summary> /// Remove the Users Session /// </summary> /// <param name="service"></param> /// <param name="request"></param> /// <returns></returns> public virtual async Task <object> LogoutAsync(IServiceBase service, Authenticate request, CancellationToken token = default) { var feature = HostContext.GetPlugin <AuthFeature>(); var session = await service.GetSessionAsync(token : token).ConfigAwait(); var referrerUrl = service.Request.GetReturnUrl() ?? (feature.HtmlLogoutRedirect != null ? service.Request.ResolveAbsoluteUrl(feature.HtmlLogoutRedirect) : null) ?? session.ReferrerUrl ?? service.Request.GetHeader("Referer").NotLogoutUrl() ?? this.RedirectUrl; session.OnLogout(service); AuthEvents.OnLogout(service.Request, session, service); await service.RemoveSessionAsync(token).ConfigAwait(); if (feature != null && feature.DeleteSessionCookiesOnLogout) { service.Request.Response.DeleteSessionCookies(); service.Request.Response.DeleteJwtCookie(); } if (service.Request.ResponseContentType == MimeTypes.Html && !string.IsNullOrEmpty(referrerUrl)) { return(service.Redirect(LogoutUrlFilter(CreateAuthContext(service, session), referrerUrl))); } return(new AuthenticateResponse()); }