[feature/oauth] Consolidate repeated query into one function

PHPBB3-11673