The line “You can only have the thing you need if you are not in need of it” does not appear in Harry Potter and the Sorcerer’s/Philosopher’s Stone.
It originates from Mark Manson’s The Subtle Art of Not Giving a F*ck (2016)—a modern self-help bestseller. The philosophical tone resembles Dumbledore-esque wisdom, causing frequent misattribution.