private function authenticatedToken(TokenInterface $token, UserInterface $user = null) { if (!$token instanceof OAuth2Token) { throw new Exception("token should be instance of OAuth2Token"); } $authenticatedToken = new OAuth2Token($token->getClient(), $user, $token->getCredentials(), $this->providerKey, $this->getRoles($token, $user)); $authenticatedToken->setAttributes($token->getAttributes()); return $authenticatedToken; }