Esempio n. 1
0
// OauthGithub link connection and user.
func OauthGithub(c *gin.Context) (int, error) {
	var authResponse oauth2.AuthResponse
	var oauthUser OauthUser
	c.BindWith(&authResponse, binding.Form)
	log.Debugf("oauthRedirect form: %v", authResponse)
	response, token, err := oauth2.OauthRequest(github.RequestURL, github.Config, authResponse)
	if err != nil {
		log.Error("get response error")
		return http.StatusInternalServerError, err
	}
	githubUser, err := SetGithubUser(response)
	if err != nil {
		log.Error("SetGithubUser error")
		return http.StatusInternalServerError, err
	}
	modelHelper.AssignValue(&oauthUser, githubUser)
	oauthUser.Id = strconv.Itoa(githubUser.UserId)
	log.Debugf("\noauthUser item : %v", oauthUser)
	status, err := LoginOrCreateOauthUser(c, &oauthUser, github.ProviderId, token)
	if err != nil {
		log.Errorf("LoginOrCreateOauthUser error: %d", status)
		return status, err
	}
	return http.StatusSeeOther, nil
}
Esempio n. 2
0
// OauthFacebook link connection and user.
func OauthFacebook(c *gin.Context) (int, error) {
	var authResponse oauth2.AuthResponse
	var oauthUser OauthUser
	c.BindWith(&authResponse, binding.Form)
	log.Debugf("oauthRedirect form: %v", authResponse)
	response, token, err := oauth2.OauthRequest(facebook.RequestURL, facebook.Config, authResponse)
	if err != nil {
		return http.StatusInternalServerError, err
	}
	facebookUser, err := SetFacebookUser(response)
	modelHelper.AssignValue(&oauthUser, facebookUser)
	log.Debugf("\noauthUser item : %v", oauthUser)
	if err != nil {
		return http.StatusInternalServerError, err
	}
	status, err := LoginOrCreateOauthUser(c, &oauthUser, facebook.ProviderId, token)
	if err != nil {
		return status, err
	}
	return http.StatusSeeOther, nil
}
Esempio n. 3
0
// OauthGoogle link connection and user.
func OauthGoogle(c *gin.Context) (int, error) {
	log.Debugf("c.Request.URL : %s", c.Request.URL)
	var authResponse oauth2.AuthResponse
	var oauthUser OauthUser
	c.BindWith(&authResponse, binding.Form)
	log.Debugf("oauthRedirect form: %v", authResponse)
	response, token, err := oauth2.OauthRequest(google.RequestURL, google.Config, authResponse)
	if err != nil {
		return http.StatusInternalServerError, err
	}
	googleUser, err := SetGoogleUser(response)
	if err != nil {
		return http.StatusInternalServerError, err
	}
	modelHelper.AssignValue(&oauthUser, googleUser)
	oauthUser.Email = googleUser.Emails[0].Value
	oauthUser.ImageUrl = googleUser.Image.URL
	status, err := LoginOrCreateOauthUser(c, &oauthUser, google.ProviderId, token)
	if err != nil {
		return status, err
	}
	return http.StatusSeeOther, nil
}