refactor deprecated methodes
This commit is contained in:
@@ -28,13 +28,13 @@ class KeycloakBearerAuthenticator extends AbstractAuthenticator
|
|||||||
|
|
||||||
public function supports(Request $request): ?bool
|
public function supports(Request $request): ?bool
|
||||||
{
|
{
|
||||||
return $request->headers->has('Authorization');
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function authenticate(Request $request): PassportInterface
|
public function authenticate(Request $request): PassportInterface
|
||||||
{
|
{
|
||||||
$token = $request->headers->get('Authorization');
|
$token = $request->headers->get('Authorization');
|
||||||
if (null === $token) {
|
if (null === $token || empty($token)) {
|
||||||
// The token header was empty, authentication fails with HTTP Status
|
// The token header was empty, authentication fails with HTTP Status
|
||||||
// Code 401 "Unauthorized"
|
// Code 401 "Unauthorized"
|
||||||
throw new CustomUserMessageAuthenticationException('Token is not present in the request headers');
|
throw new CustomUserMessageAuthenticationException('Token is not present in the request headers');
|
||||||
|
|||||||
@@ -245,6 +245,14 @@ class KeycloakBearerUser implements UserInterface, \Serializable
|
|||||||
return $this->preferred_username;
|
return $this->preferred_username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUserIdentifier(): string
|
||||||
|
{
|
||||||
|
return $this->preferred_username;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes sensitive data from the user.
|
* Removes sensitive data from the user.
|
||||||
*
|
*
|
||||||
@@ -298,4 +306,4 @@ class KeycloakBearerUser implements UserInterface, \Serializable
|
|||||||
$this->accessToken
|
$this->accessToken
|
||||||
) = unserialize($serialized, ['allowed_classes' => false]);
|
) = unserialize($serialized, ['allowed_classes' => false]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace ABEL\Bundle\keycloakBearerOnlyAdapterBundle\Security\User;
|
|||||||
|
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
|
||||||
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
||||||
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
|
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
@@ -115,11 +116,11 @@ class KeycloakBearerUserProvider implements UserProviderInterface{
|
|||||||
$jwt = json_decode($response->getBody(), true);
|
$jwt = json_decode($response->getBody(), true);
|
||||||
|
|
||||||
if (!$jwt['active']) {
|
if (!$jwt['active']) {
|
||||||
throw new \UnexpectedValueException('The token does not exist or is not valid anymore');
|
throw new CustomUserMessageAuthenticationException('The token does not exist or is not valid anymore');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($jwt['resource_access'][$this->client_id])) {
|
if (!isset($jwt['resource_access'][$this->client_id])) {
|
||||||
throw new \UnexpectedValueException('The token does not have the necessary permissions!');
|
throw new CustomUserMessageAuthenticationException('The token does not have the necessary permissions!');
|
||||||
}
|
}
|
||||||
|
|
||||||
return new KeycloakBearerUser(
|
return new KeycloakBearerUser(
|
||||||
@@ -142,4 +143,4 @@ class KeycloakBearerUserProvider implements UserProviderInterface{
|
|||||||
{
|
{
|
||||||
return $this->loadUserByIdentifier($username);
|
return $this->loadUserByIdentifier($username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user