It's absolutely amazing that we can even figure out molecules at that distance. I'm sure it's accurate but it's so sciency to me that it might as well be made up entirely. I can't begin to fathom that process.
It's basically "look at far away object with a fancy pair of sunglasses."
Because of quantum mechanical reasons, molecules can only absorb and emit light with very particular energy levels (which correspond to frequency/wavelength). So point your camera at an exoplanet and carefully record the amount of the light you see at different wavelengths. My guess is that it's based on IR spectroscopy, since there's a nice region of that spectra where you can "fingerprint" a molecule based on the peaks in absorption in that region (it's literally called the "fingerprint region").
I write about it in on page 5 of my coffee table photobook: