I want to implement an authentication flow as a middleware for the rest APIs. The way I want to execute is: