Refactor authenticate to use header