Created
July 6, 2020 19:53
-
-
Save blafasel42/117f66f3b3023a4ff62206a4449a09cb to your computer and use it in GitHub Desktop.
Controlle for Nginx sub request authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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