go - How to integrate Oauth2 using golang? -
i have rest api created in golang
works encrypted key authenticate requests. want integrate oauth2
authentication. couldn't find proper tutorial integrate oauth2 in project. have login api handler written in golang.
func userlogin(c *gin.context){ response := responsecontroller{} var userdata userloginstruct usererr := json.newdecoder(c.request.body).decode(&userdata) if usererr != nil { response = responsecontroller{ config.failurecode, config.failureflag, "data not in proper format", nil, } getresponse(c, response) return } var err error usersaveddata, getusererror := models.getcompleteuser(bson.m{"email_id": userdata.username}) if getusererror != nil{ response = responsecontroller{ config.failurecode, config.failureflag, "invalid email", nil, } getresponse(c, response) return } //hashedpassword err = bcrypt.comparehashandpassword([]byte(usersaveddata.password), []byte(userdata.password)) var sessiondata models.session sessiondata.userid = usersaveddata.id sessiondata.role = usersaveddata.role sessiondata.createdon = time.now().unix() if err != nil { response = responsecontroller{ config.failurecode, config.failurecode, config.failuremsg, nil, } } else { _ = models.savesession(sessiondata) usersaveddata.password = "" _ = models.updateuser(usersaveddata.id, bson.m{"$set": &models.user{lastlogin: time.now().unix()}}) response = responsecontroller{ config.successcode, config.successflag, config.successmsg, usersaveddata, } } getresponse(c, response) }
this handler checks user credentials email , password , if right session created. how can use token based system using oauth2 handler?
thanks!
Comments
Post a Comment