The Messenger of Allah ﷺ came out to us when we were nine in number and said, "There will come after me rulers. Whoever endorses their lies and supports them in their oppression is not of me, and I am not of him, and he will not come to me at the Pool. But whoever does not endorse their lies and does not support them in their oppression is of me, and I am of him, and he will come to me at the Pool."
أخبرنا عمرو بن علي قال حدثنا يحيى عن سفيان عن أبي حصين عن الشعبي عن عاصم العدوي
خرج علينا رسول الله ﷺ ونحن تسعة فقال إنه ستكون بعدي أمراء من صدقهم بكذبهم وأعانهم على ظلمهم فليس مني ولست منه وليس بوارد علي الحوض ومن لم يصدقهم بكذبهم ولم يعنهم على ظلمهم فهو مني وأنا منه وهو وارد علي الحوض
Its chain of transmission is sahih. Tirmidhi narrated it in "the Book of Tribulations, the chapter on the warning against agreeing with wicked rulers," Hadith 2259, from the hadith of Sufyan Thawri, through him, and he said, sahih ghareeb. It is also in Al-Kubra, Hadith 7830.