public function authenticate(TokenInterface $token)
    {
        $user = $this->userProvider->loadUserByApiKey($this->encoder->encodePassword($token->getCredentials()));

        if (!$user || !($user instanceof UserInterface)) {
            throw new AuthenticationException('Bad credentials');
        }

        $token = new ApiKeyToken($token->getCredentials(), $user->getRoles());
        $token->setUser($user);

        return $token;
    }