Skip to content

Instantly share code, notes, and snippets.

@blafasel42
Created July 6, 2020 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blafasel42/117f66f3b3023a4ff62206a4449a09cb to your computer and use it in GitHub Desktop.
Save blafasel42/117f66f3b3023a4ff62206a4449a09cb to your computer and use it in GitHub Desktop.
Controlle for Nginx sub request authentication
<?php
namespace App\Controller;
use ...
/**
* Class AuthenticationController
*
* @package User\UserBundle\Controller
*/
class AuthenticationController extends AbstractController
{
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'routing_prefix' => '',
]);
}
/**
* Endpoint that let's SSO-Proxy know if the user is authenticated.
*
* @return Response
*
* @Route(path="/auth", name="auth_auth")
*/
public function authAction(TokenStorageInterface $token)
{
$securityUser = $this->getUser();
if ($securityUser === null) {
return new Response("", Response::HTTP_UNAUTHORIZED);
}
$r= new Response(
'',
Response::HTTP_OK,
[
'account-id' => $user->getAccountId(),
'user-id' => $user->getId(),
AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER => 1
]
);
$r->setPublic();
$r->setMaxAge(60);
return $r;
}
/**
* @Route(path="/logout", name="app_logout")
*/
public function logoutAction(Request $request)
{
// This should not be called. It should be handled by symfony security
throw new \LogicException("This should not be called.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment