正常的版本
This commit is contained in:
parent
e4e9339071
commit
c13225d2fa
2
go.mod
2
go.mod
|
@ -30,7 +30,7 @@ require (
|
|||
)
|
||||
|
||||
require (
|
||||
github.com/474420502/requests v1.39.0
|
||||
github.com/474420502/requests v1.40.0
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/tidwall/gjson v1.12.0
|
||||
|
|
4
go.sum
4
go.sum
|
@ -36,8 +36,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
|
|||
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
github.com/474420502/random v0.4.1 h1:HUUyLXRWMijVb7CJoEC16f0aFQOW25Lkr80Mut6PoKU=
|
||||
github.com/474420502/requests v1.39.0 h1:ICrBfgkw3Jtatv/tKvDsKhIIFg0HslOE7BSIgfh2qO0=
|
||||
github.com/474420502/requests v1.39.0/go.mod h1:r1Uwbbq/t3Cn95VOfgJjZmD7sfwp+gjldq/zDncNYRc=
|
||||
github.com/474420502/requests v1.40.0 h1:VDuLxSG/3IGBvMfjPV8+o7s1l5mOwLAgfo5Og6vMAJw=
|
||||
github.com/474420502/requests v1.40.0/go.mod h1:2SCVzim0ONFYG09g/GrM7RTeJIC6qTyZfnohsjnG5C8=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||
|
|
|
@ -7,14 +7,15 @@ Auth:
|
|||
AccessSecret: fusen2023
|
||||
AccessExpire: 2592000
|
||||
RefreshAfter: 1592000
|
||||
|
||||
OAuth:
|
||||
- name: google
|
||||
appid: 1064842923358-e94msq2glj6qr4lrva9ts3q8h.apps.googleusercontent.com
|
||||
secret: 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
|
||||
|
||||
- name: facebook
|
||||
appid: 1095953604597065
|
||||
secret: b146872550a190d5275b1420c212002e
|
||||
OAuth:
|
||||
google:
|
||||
appid: "1064842923358-e94msq2glj6qr4lrva9ts3q8h.apps.googleusercontent.com"
|
||||
secret: "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"
|
||||
|
||||
facebook:
|
||||
appid: "1095953604597065"
|
||||
secret: "b146872550a190d5275b1420c212002e"
|
||||
|
||||
Stripe:
|
||||
SK: sk_test_51IisojHygnIJZeghPVSBhkwySfcyDV4SoAduIxu3J7bvSJ9cZMD96LY1LO6SpdbYquLJX5oKvgEBB67KT9pecfCy00iEC4pp9y
|
||||
SK: "sk_test_51IisojHygnIJZeghPVSBhkwySfcyDV4SoAduIxu3J7bvSJ9cZMD96LY1LO6SpdbYquLJX5oKvgEBB67KT9pecfCy00iEC4pp9y"
|
||||
|
|
|
@ -21,6 +21,7 @@ func main() {
|
|||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
|
||||
conf.MustLoad(*configFile, &c)
|
||||
c.Timeout = int64(time.Second * 15)
|
||||
|
||||
|
|
|
@ -6,18 +6,22 @@ import (
|
|||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
type OAuth struct {
|
||||
Name string `yaml:"name"`
|
||||
Appid string `yaml:"appid"`
|
||||
Secret string `yaml:"secret"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
SourceMysql string
|
||||
Auth types.Auth
|
||||
|
||||
OAuth []OAuth
|
||||
OAuth struct {
|
||||
Google struct {
|
||||
Appid string
|
||||
Secret string
|
||||
}
|
||||
|
||||
Facebook struct {
|
||||
Appid string
|
||||
Secret string
|
||||
}
|
||||
}
|
||||
|
||||
Stripe struct {
|
||||
SK string
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"context"
|
||||
|
||||
|
@ -12,6 +13,7 @@ import (
|
|||
|
||||
"github.com/474420502/requests"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"golang.org/x/net/proxy"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
)
|
||||
|
@ -34,20 +36,35 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us
|
|||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
dialer, err := proxy.SOCKS5("tcp", "127.0.0.1:1080", nil, proxy.Direct)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
customClient := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Dial: dialer.Dial,
|
||||
},
|
||||
}
|
||||
|
||||
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, customClient)
|
||||
|
||||
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,
|
||||
ClientID: l.svcCtx.Config.OAuth.Google.Appid,
|
||||
ClientSecret: l.svcCtx.Config.OAuth.Google.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)
|
||||
token, err := googleOauthConfig.Exchange(ctx, req.Code)
|
||||
if err != nil {
|
||||
resp.SetStatus(basic.CodeApiErr)
|
||||
}
|
||||
ses := requests.NewSession()
|
||||
ses.Config().SetProxy("socks5://127.0.0.1:1080")
|
||||
|
||||
r, err := requests.Get("https://www.googleapis.com/oauth2/v2/userinfo" + token.AccessToken).Execute()
|
||||
r, err := ses.Get("https://www.googleapis.com/oauth2/v2/userinfo?access_token=" + token.AccessToken).Execute()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user