code: private function createResponseRedirect($redirect,Request $request){
  		$response=new Response();
  		if($request->isAjax()){
  			$response->setStatusCode(401);
  			$response->setHeader('X-Location',$redirect);
  		}
  		else{
  			$response->redirect($redirect);
  		}
  		return $response;
  	}
docs: Check authenticate.
  
  @param string $redirect
  @param Request $request
  @return Response