diff --git a/DependencyInjection/ClientFactory.php b/DependencyInjection/ClientFactory.php
index <HASH>..<HASH> 100644
--- a/DependencyInjection/ClientFactory.php
+++ b/DependencyInjection/ClientFactory.php
@@ -395,7 +395,15 @@ class ClientFactory
                     return ['id' => $user->getUserIdentifier()];
                 }
 
-                return ['id' => $user->getUsername()];
+                // Symfony 5.4 and below use 'getUsername' ('getUserIdentifier'
+                // wasn't added to the interface until Symfony 6.0 for BC)
+                if (method_exists(UserInterface::class, 'getUsername')) {
+                    return ['id' => $user->getUsername()];
+                }
+
+                // if neither method exists then we don't know how to deal with
+                // this version of Symfony's UserInterface, so can't get an ID
+                return;
             }
 
             return ['id' => (string) $user];
Guard against future changes to UserInterface