Merge branch 'support-google-oauth' into refactor-main

This commit is contained in:
ckt1031 2023-07-25 12:22:04 +08:00
commit 04110d4b01
2 changed files with 4 additions and 20 deletions

View File

@ -35,7 +35,7 @@ func getGoogleUserInfoByCode(codeFromURLParamaters string, host string) (*Google
RequestClient := &http.Client{}
accessTokenBody := bytes.NewBuffer([]byte(fmt.Sprintf(
"code=%s&client_id=%s&client_secret=%s&redirect_uri=%s/oauth/google&grant_type=authorization_code",
"code=%s&client_id=%s&client_secret=%s&redirect_uri=https://%s/oauth/google&grant_type=authorization_code",
codeFromURLParamaters, common.GoogleClientId, common.GoogleClientSecret, host,
)))
@ -112,15 +112,7 @@ func GoogleOAuth(c *gin.Context) {
}
code := c.Query("code")
// Get protocal whether http or https and host
host := c.Request.Host
if c.Request.TLS == nil {
host = "http://" + host
} else {
host = "https://" + host
}
googleUser, err := getGoogleUserInfoByCode(code, host)
googleUser, err := getGoogleUserInfoByCode(code, c.Request.Host)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
@ -187,15 +179,7 @@ func GoogleBind(c *gin.Context) {
}
code := c.Query("code")
// Get protocal whether http or https and host
host := c.Request.Host
if c.Request.TLS == nil {
host = "http://" + host
} else {
host = "https://" + host
}
googleUser, err := getGoogleUserInfoByCode(code, host)
googleUser, err := getGoogleUserInfoByCode(code, c.Request.Host)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,

View File

@ -189,7 +189,7 @@ func (user *User) FillUserByWeChatId() error {
}
func (user *User) FillUserByGoogleId() error {
if user.WeChatId == "" {
if user.GoogleId == "" {
return errors.New("Google id 为空!")
}
DB.Where(User{GoogleId: user.GoogleId}).First(user)