Updated and added code for authenticate using api