Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
ahmad-zuhd:2140ʿAbdullāh > Sufyān b. Wakīʿ > Ibn ʿUyaynah > ʿAmr b. Dīnār

[Machine] Muhammad ibn Ali said: "Invoke Allah in what you love, and when what you dislike happens, you will not disobey Allah in what you love."  

الزهد لأحمد:٢١٤٠حَدَّثَنَا عَبْدُ اللَّهِ حَدَّثَنَا سُفْيَانُ بْنُ وَكِيعٍ حَدَّثَنَا ابْنُ عُيَيْنَةَ عَنْ عَمْرِو بْنِ دِينَارٍ قَالَ

قَالَ مُحَمَّدُ بْنُ عَلِيٍّ «ادْعُ اللَّهَ فِيمَا تُحِبُّ فَإِذَا وَقَعَ الَّذِي تَكْرَهُ لَمْ تُخَالِفِ اللَّهَ فِيمَا أَحَبَّ»