Create your text on a background.
Duplicate the text + background
Select the duplicated objects and click/apply ‘trim’ (see image below)
Apply shadow on the trimmed object, use the ‘flat preset’ then select ‘break shadow apart’.
Select the shadow (the one you just broke apart) and place inside the text (remember you had duplicated the objects) Adjust the shadow where applicable.