-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SDK-4733): Implement support for Back-Channel Logout (#167)
- Loading branch information
Showing
5 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Backchannel Logout | ||
|
||
The Auth0 Symfony SDK supports [Backchannel Logout](https://auth0.com/docs/authenticate/login/logout/back-channel-logout) from v5.2 onward. To use this feature, some additional configuration is necessary: | ||
|
||
1. **Add a new route to your application.** This route must be publicly accessible. Auth0 will use it to send backchannel logout requests to your application. For example, from your `config/routes.yaml` file: | ||
|
||
```yaml | ||
backchannel: # Retrieve backchannel logout tokens from Auth0 | ||
path: /backckannel | ||
controller: Auth0\Symfony\Controllers\BackchannelController::handle | ||
methods: POST | ||
``` | ||
2. **Configure your Auth0 tenant to use Backchannel Logout.** See the [Auth0 documentation](https://auth0.com/docs/authenticate/login/logout/back-channel-logout/configure-back-channel-logout) for more information on how to do this. Please ensure you point the Logout URI to the backchannel route we just added to your application. |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Auth0\Symfony\Controllers; | ||
|
||
use Auth0\SDK\Auth0; | ||
use Auth0\Symfony\Contracts\Controllers\AuthenticationControllerInterface; | ||
use Auth0\Symfony\Security\Authenticator; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response}; | ||
use Throwable; | ||
|
||
use function is_string; | ||
|
||
final class BackchannelLogoutController extends AbstractController implements AuthenticationControllerInterface | ||
{ | ||
public function __construct( | ||
private Authenticator $authenticator, | ||
) { | ||
} | ||
|
||
public function handle(Request $request): Response | ||
{ | ||
if ('POST' !== $request->getMethod()) { | ||
return new Response('', Response::HTTP_METHOD_NOT_ALLOWED); | ||
} | ||
|
||
$logoutToken = $request->get('logout_token'); | ||
|
||
if (! is_string($logoutToken)) { | ||
return new Response('', Response::HTTP_BAD_REQUEST); | ||
} | ||
|
||
$logoutToken = trim($logoutToken); | ||
|
||
if ('' === $logoutToken) { | ||
return new Response('', Response::HTTP_BAD_REQUEST); | ||
} | ||
|
||
try { | ||
$this->getSdk()->handleBackchannelLogout($logoutToken); | ||
} catch (Throwable $throwable) { | ||
return new Response($throwable->getMessage(), Response::HTTP_BAD_REQUEST); | ||
} | ||
|
||
return new Response('', Response::HTTP_OK); | ||
} | ||
|
||
private function getSdk(): Auth0 | ||
{ | ||
return $this->authenticator->service->getSdk(); | ||
} | ||
} |