Merge branch 'support-google-oauth' into refactor-main
This commit is contained in:
commit
04110d4b01
@ -35,7 +35,7 @@ func getGoogleUserInfoByCode(codeFromURLParamaters string, host string) (*Google
|
|||||||
RequestClient := &http.Client{}
|
RequestClient := &http.Client{}
|
||||||
|
|
||||||
accessTokenBody := bytes.NewBuffer([]byte(fmt.Sprintf(
|
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,
|
codeFromURLParamaters, common.GoogleClientId, common.GoogleClientSecret, host,
|
||||||
)))
|
)))
|
||||||
|
|
||||||
@ -112,15 +112,7 @@ func GoogleOAuth(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
code := c.Query("code")
|
code := c.Query("code")
|
||||||
|
|
||||||
// Get protocal whether http or https and host
|
googleUser, err := getGoogleUserInfoByCode(code, c.Request.Host)
|
||||||
host := c.Request.Host
|
|
||||||
if c.Request.TLS == nil {
|
|
||||||
host = "http://" + host
|
|
||||||
} else {
|
|
||||||
host = "https://" + host
|
|
||||||
}
|
|
||||||
|
|
||||||
googleUser, err := getGoogleUserInfoByCode(code, host)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
@ -187,15 +179,7 @@ func GoogleBind(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
code := c.Query("code")
|
code := c.Query("code")
|
||||||
|
|
||||||
// Get protocal whether http or https and host
|
googleUser, err := getGoogleUserInfoByCode(code, c.Request.Host)
|
||||||
host := c.Request.Host
|
|
||||||
if c.Request.TLS == nil {
|
|
||||||
host = "http://" + host
|
|
||||||
} else {
|
|
||||||
host = "https://" + host
|
|
||||||
}
|
|
||||||
|
|
||||||
googleUser, err := getGoogleUserInfoByCode(code, host)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
|
@ -189,7 +189,7 @@ func (user *User) FillUserByWeChatId() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) FillUserByGoogleId() error {
|
func (user *User) FillUserByGoogleId() error {
|
||||||
if user.WeChatId == "" {
|
if user.GoogleId == "" {
|
||||||
return errors.New("Google id 为空!")
|
return errors.New("Google id 为空!")
|
||||||
}
|
}
|
||||||
DB.Where(User{GoogleId: user.GoogleId}).First(user)
|
DB.Where(User{GoogleId: user.GoogleId}).First(user)
|
||||||
|
Loading…
Reference in New Issue
Block a user