The Messenger of Allah ﷺ said, "Whoever obeys me has obeyed Allah, and whoever disobeys me has disobeyed Allah. Whoever obeys my appointed leader has obeyed me, and whoever disobeys my appointed leader has disobeyed me."
أن رسول الله ﷺ قال: من أطاعني فقد أطاع الله، ومن عصاني فقد عصى الله، ومن أطاع أميري فقد أطاعني، ومن عصى أميري فقد عصاني.
Bukhari narrated it in the Book of Rulings (7137), and Muslim in the Book of Leadership (1835:33), both from the hadith of Abdullah bin Wahb, who said, Yunus told me, from Ibn Shihab, who said, Abu Salama bin Abdul-Rahman told me that he heard Abu Hurairah say, and then he mentioned it, and their wording is the same.