The Prophet ﷺ said, "While Ayub was bathing naked, golden locusts began falling upon him, and Ayub started gathering them into his garment. His Lord called out to him, 'Ayub, have I not made you rich enough to have no need for what you see?'Ayub replied, 'Yes, by Your might, but I can never do without Your blessing.'"
عن النبي ﷺ قال: بينا أيوب يغتسل عريانا فخر عليه جراد من ذهب، فجعل أيوب يحتثي في ثوبه، فناداه ربه: يا أيوب! ألم أكن أغنيتك عما ترى؟ قال: بلى وعزتك، ولكن لا غنى بي عن بركتك.
Bukhari narrated it in the Book of Ghusl (279) with the aforementioned chain of transmission. Nawawi said, "As for a man uncovering his private parts while alone, where no human being sees him, if there is a need for it, then it is permissible. But if there is no need for it, the scholars differ over whether it is disliked or forbidden, and the most correct view according to us is that it is forbidden."