[SD-714][SD-718] Refactor the authentication code into two different modules.