修复proxy不传递query参数的问题
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user