refactored implicit grant middleware