修复proxy不传递query参数的问题
This commit is contained in:
@@ -7,9 +7,9 @@ import (
|
||||
)
|
||||
|
||||
type OAuth struct {
|
||||
Name string `json:"name"`
|
||||
Appid string `json:"appid"`
|
||||
Secret string `json:"secret"`
|
||||
Name string `yaml:"name"`
|
||||
Appid string `yaml:"appid"`
|
||||
Secret string `yaml:"secret"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
|
||||
@@ -68,15 +68,10 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Handler: UserOderDeleteHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/user/oauth2/login/google",
|
||||
Handler: UserGoogleLoginHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/user/oauth2/login",
|
||||
Handler: UserOAuth2LoginHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -53,6 +54,7 @@ func UserGoogleLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||
}
|
||||
|
||||
log.Println(r.URL.String(), r.URL.Query())
|
||||
var req types.RequestGoogleLogin
|
||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
|
||||
@@ -3,13 +3,17 @@ package logic
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"log"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/474420502/requests"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
)
|
||||
|
||||
type UserGoogleLoginLogic struct {
|
||||
@@ -30,5 +34,24 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
var googleOauthConfig = &oauth2.Config{
|
||||
RedirectURL: "http://localhost:9900/api/user/oauth2/login/google",
|
||||
ClientID: l.svcCtx.Config.OAuth[0].Appid,
|
||||
ClientSecret: l.svcCtx.Config.OAuth[0].Secret,
|
||||
Scopes: []string{"https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"},
|
||||
Endpoint: google.Endpoint,
|
||||
}
|
||||
|
||||
token, err := googleOauthConfig.Exchange(context.Background(), req.Code)
|
||||
if err != nil {
|
||||
resp.SetStatus(basic.CodeApiErr)
|
||||
}
|
||||
|
||||
r, err := requests.Get("https://www.googleapis.com/oauth2/v2/userinfo" + token.AccessToken).Execute()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Println(r.Json())
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
@@ -3,17 +3,13 @@ package logic
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"log"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/474420502/requests"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
)
|
||||
|
||||
type UserOAuth2LoginLogic struct {
|
||||
@@ -34,31 +30,6 @@ func NewUserOAuth2LoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *U
|
||||
func (l *UserOAuth2LoginLogic) UserOAuth2Login(req *types.RequestOAuth, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
switch req.Platform {
|
||||
case "google":
|
||||
var googleOauthConfig = &oauth2.Config{
|
||||
RedirectURL: "https://fusenh5.kayue.cn/api/user/oauth2/login/google",
|
||||
ClientID: l.svcCtx.Config.OAuth[0].Appid,
|
||||
ClientSecret: l.svcCtx.Config.OAuth[0].Secret,
|
||||
Scopes: []string{"https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"},
|
||||
Endpoint: google.Endpoint,
|
||||
}
|
||||
|
||||
token, err := googleOauthConfig.Exchange(context.Background(), req.Code)
|
||||
if err != nil {
|
||||
resp.SetStatus(basic.CodeApiErr)
|
||||
}
|
||||
|
||||
resp, err := requests.Get("https://www.googleapis.com/oauth2/v2/userinfo" + token.AccessToken).Execute()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Println(resp.Json())
|
||||
|
||||
case "facebook":
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
@@ -6,16 +6,10 @@ import (
|
||||
)
|
||||
|
||||
type RequestGoogleLogin struct {
|
||||
ID string `json:"id,,optional"`
|
||||
Email string `json:"email,,optional"`
|
||||
VerifiedEmail bool `json:"verified_email,,optional"`
|
||||
Name string `json:"name,,optional"`
|
||||
GivenName string `json:"given_name,,optional"`
|
||||
FamilyName string `json:"family_name,,optional"`
|
||||
Link string `json:"link,,optional"`
|
||||
Picture string `json:"picture,,optional"`
|
||||
Gender string `json:"gender,,optional"`
|
||||
Locale string `json:"locale,,optional"`
|
||||
Code string `form:"code"`
|
||||
Scope string `form:"scope"`
|
||||
AuthUser string `form:"authuser"`
|
||||
Prompt string `form:"prompt"`
|
||||
}
|
||||
|
||||
type RequestOAuth struct {
|
||||
|
||||
Reference in New Issue
Block a user