wiki/content/20201109152527-getcredentials_responsibilities_split.md

41 lines
906 B
Markdown
Raw Normal View History

2024-05-06 20:40:05 +00:00
---
2024-10-30 17:34:11 +00:00
date: 2020-11-09
2024-05-06 20:40:05 +00:00
id: 9e629f0c-33c0-45bb-a978-623b13b2ffa5
title: getCredentials() responsibilities split
---
Since [Symfony 4.0](20201109140137-symfony_4_0) `getCredentials()`
responsibilities has been split into 2 methods:
``` php
// BEFORE
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
class TokenAuthenticator extends AbstractGuardAuthenticator
{
public function getCredentials(Request $request)
{
if (!$token = $request->headers->get('X-AUTH-TOKEN')) {
return null;
}
return ['token' => $token];
}
}
// AFTER
class TokenAuthenticator extends AbstractGuardAuthenticator
{
public function supports(Request $request)
{
return $request->headers->has('X-AUTH-TOKEN');
}
public function getCredentials(Request $request)
{
return ['token' => $request->headers->get('X-AUTH-TOKEN')];
}
}
```