Junada bin Abu Umaya reported,

We came to visit Ubada bin Samit while he was ill and said, "May Allah grant you well-being. Tell us a hadith you heard from the Messenger of Allah ﷺ through which Allah may bring benefit."He said, "The Messenger of Allah ﷺ called us and we pledged allegiance to him. Among the commitments he took from us was that we pledged to listen and obey in what we liked and what we disliked, in hardship and in ease, and even when others were given preference over us, and that we would not contest authority with those in power." He added, "Unless you see open disbelief for which you have clear proof from Allah."

Muslim 4771

Sahih

حدثنا أحمد بن عبد الرحمن بن وهب بن مسلم حدثنا عمي عبد الله بن وهب حدثنا عمرو بن الحارث حدثني بكير عن بسر بن سعيد

عن جنادة بن أبي أمية قال

دخلنا على عبادة بن الصامت وهو مريض فقلنا حدثنا أصلحك الله بحديث ينفع الله به سمعته من رسول الله ﷺ فقال دعانا رسول الله ﷺ فبايعناه فكان فيما أخذ علينا أن بايعنا على السمع والطاعة في منشطنا ومكرهنا وعسرنا ويسرنا وأثرة علينا وأن لا ننازع الأمر أهله قال إلا أن تروا كفرا بواحا عندكم من الله فيه برهان

مسلم 4771صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Leadership
Chapter
Obligation of obeying leaders in matters other than disobedience and its prohibition in disobedience
Numbering
Darussalam 4771
Muslim 4771