public ActionResult SignOut() { Uri externalLogOffUri = null; if (this.Request.IsAuthenticated) { var ctx = Request.GetOwinContext(); ctx.Authentication.SignOut(CookieConstants.ApplicationCookieAuthenticationType); IdentityProviderClientConfigurationElement providerClient = OpenIdConnectUtilities.GetCurrentProviderSettings(); ////ctx.Authentication.SignOut(providerClient.Name); // Clean up openId nonce cookie. This is just a workaround. Ideally, we should be calling 'ctx.Authentication.SignOut(providerClient.Name)' //// Begin workaround. foreach (string cookieName in ControllerContext.HttpContext.Request.Cookies.AllKeys) { if (cookieName.StartsWith("OpenIdConnect.nonce.", StringComparison.OrdinalIgnoreCase)) { OpenIdConnectUtilities.RemoveCookie(cookieName); break; } } //// End workaround. externalLogOffUri = providerClient.LogOffUrl; } OpenIdConnectUtilities.RemoveCookie(OpenIdConnectUtilities.CookieCurrentProvider); ServiceUtilities.CleanUpOnSignOutOrAuthFailure(this.HttpContext); return(this.View(SignInController.SignOutViewName, externalLogOffUri)); }
/// <summary> /// Called when an exception is thrown. /// </summary> /// <param name="filterContext">The filter context.</param> protected override void OnException(ExceptionContext filterContext) { if (filterContext == null) { throw new ArgumentNullException("filterContext"); } base.OnException(filterContext); Exception currentException = null; if (filterContext.Exception as AggregateException != null) { currentException = filterContext.Exception.InnerException; } else { currentException = filterContext.Exception; } if (currentException as UserAuthorizationException != null || currentException as UserAuthenticationException != null || currentException as AuthenticationException != null || currentException as SecurityException != null) { ServiceUtilities.CleanUpOnSignOutOrAuthFailure(this.HttpContext); var ctx = this.HttpContext.GetOwinContext(); ctx.Authentication.Challenge(CookieConstants.ApplicationCookieAuthenticationType); filterContext.Result = new HttpUnauthorizedResult("User must sign in"); filterContext.ExceptionHandled = true; RetailLogger.Log.OnlineStoreForceSignOutOnAuthenticatedFlowError( filterContext.HttpContext.Response.StatusCode, filterContext.HttpContext.Response.RedirectLocation, filterContext.Exception, filterContext.Exception.InnerException); } else { RetailLogger.Log.OnlineStoreLogUnexpectedException( filterContext.RequestContext.HttpContext.Request.Url.AbsoluteUri, filterContext.Exception, filterContext.Exception.InnerException); } }
/// <summary> /// Called when an exception is thrown. /// </summary> /// <param name="filterContext">The filter context.</param> protected override void OnException(ExceptionContext filterContext) { if (filterContext == null) { throw new ArgumentNullException("filterContext"); } base.OnException(filterContext); Exception currentException = null; if (filterContext.Exception as AggregateException != null) { currentException = filterContext.Exception.InnerException; } else { currentException = filterContext.Exception; } if (currentException as UserAuthorizationException != null || currentException as UserAuthenticationException != null || currentException as AuthenticationException != null) { ServiceUtilities.CleanUpOnSignOutOrAuthFailure(this.HttpContext); RetailProxyException retailProxyException = currentException as RetailProxyException; ResponseError responseError = new ResponseError() { ErrorCode = retailProxyException.ErrorResourceId, LocalizedErrorMessage = retailProxyException.LocalizedMessage, }; filterContext.Result = this.Json(responseError); filterContext.HttpContext.Response.StatusCode = 310; filterContext.HttpContext.Response.RedirectLocation = "/SignIn"; filterContext.ExceptionHandled = true; RetailLogger.Log.OnlineStoreForceSignOutOnAuthenticatedFlowError( filterContext.HttpContext.Response.StatusCode, filterContext.HttpContext.Response.RedirectLocation, filterContext.Exception, filterContext.Exception.InnerException); } else { if (currentException as CartValidationException != null) { CartValidationException cartValidationException = (CartValidationException)currentException; if (string.Equals(cartValidationException.ErrorResourceId, DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_CartNotFound.ToString(), StringComparison.OrdinalIgnoreCase)) { ServiceUtilities.ClearCartCookies(this.HttpContext); } } IEnumerable <ResponseError> responseErrors = Utilities.GetResponseErrorsFromException(currentException); filterContext.ExceptionHandled = true; filterContext.Result = this.Json(responseErrors); filterContext.HttpContext.Response.StatusCode = 400; RetailLogger.Log.OnlineStoreLogUnexpectedException( filterContext.RequestContext.HttpContext.Request.Url.AbsoluteUri, filterContext.Exception, filterContext.Exception.InnerException); } }