调整
This commit is contained in:
parent
bc1bfb8766
commit
338fe67a0e
@ -71,7 +71,7 @@ func (this *VIPApi) Bind(c *gin.Context) {
|
|||||||
|
|
||||||
passportContext := c.Copy()
|
passportContext := c.Copy()
|
||||||
passportContext.Request.Header.Set("Authorization", reqObj.Passport_jwt)
|
passportContext.Request.Header.Set("Authorization", reqObj.Passport_jwt)
|
||||||
middleware.JwtAuth(passportContext)
|
middleware.JwtAuthOnly(passportContext)
|
||||||
passport_addr := passportContext.GetString("account_address")
|
passport_addr := passportContext.GetString("account_address")
|
||||||
if passport_addr == "" {
|
if passport_addr == "" {
|
||||||
f5.RspErr(c, 1, "bad request passport")
|
f5.RspErr(c, 1, "bad request passport")
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"q5"
|
|
||||||
"f5"
|
"f5"
|
||||||
"main/mt"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"jccommon"
|
"jccommon"
|
||||||
|
"main/mt"
|
||||||
|
"q5"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,8 +19,23 @@ func JwtAuth(c *gin.Context) {
|
|||||||
internalJwtAuth(c, false)
|
internalJwtAuth(c, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func JwtAuthOnly(c *gin.Context) {
|
||||||
|
tokenHeader := c.Request.Header.Get("Authorization")
|
||||||
|
jwtToken := ""
|
||||||
|
if len(tokenHeader) > 8 {
|
||||||
|
jwtToken = tokenHeader[7:len(tokenHeader)]
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpStrings := q5.StrSplit(jwtToken, ".")
|
||||||
|
if len(tmpStrings) > 3 {
|
||||||
|
internalMetaMaskJwtAuth(c, jwtToken, false)
|
||||||
|
} else {
|
||||||
|
internalImmutJwtAuth(c, jwtToken, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
'Authorization Bearer {JwtToken}'
|
'Authorization Bearer {JwtToken}'
|
||||||
*/
|
*/
|
||||||
func internalJwtAuth(c *gin.Context, maybe bool) {
|
func internalJwtAuth(c *gin.Context, maybe bool) {
|
||||||
tokenHeader := c.Request.Header.Get("Authorization")
|
tokenHeader := c.Request.Header.Get("Authorization")
|
||||||
@ -38,40 +54,40 @@ func internalJwtAuth(c *gin.Context, maybe bool) {
|
|||||||
|
|
||||||
tmpStrings := q5.StrSplit(jwtToken, ".")
|
tmpStrings := q5.StrSplit(jwtToken, ".")
|
||||||
if len(tmpStrings) > 3 {
|
if len(tmpStrings) > 3 {
|
||||||
internalMetaMaskJwtAuth(c, jwtToken)
|
internalMetaMaskJwtAuth(c, jwtToken, true)
|
||||||
} else {
|
} else {
|
||||||
internalImmutJwtAuth(c, jwtToken)
|
internalImmutJwtAuth(c, jwtToken, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func internalImmutJwtAuth(c *gin.Context, jwtToken string) {
|
func internalImmutJwtAuth(c *gin.Context, jwtToken string, rsperr bool) {
|
||||||
params := map[string]string{
|
params := map[string]string{
|
||||||
"c": "Jwt",
|
"c": "Jwt",
|
||||||
"a": "verify",
|
"a": "verify",
|
||||||
}
|
}
|
||||||
jsonReqObj := &struct {
|
jsonReqObj := &struct {
|
||||||
JwksUri string `json:"jwksUri"`
|
JwksUri string `json:"jwksUri"`
|
||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}{
|
}{
|
||||||
JwksUri: mt.Table.Config.GetJwksUri(),
|
JwksUri: mt.Table.Config.GetJwksUri(),
|
||||||
Data: jwtToken,
|
Data: jwtToken,
|
||||||
}
|
}
|
||||||
jsonRspObj := &struct {
|
jsonRspObj := &struct {
|
||||||
ErrCode interface{} `json:"errcode"`
|
ErrCode interface{} `json:"errcode"`
|
||||||
ErrMsg string `json:"errmsg"`
|
ErrMsg string `json:"errmsg"`
|
||||||
Decoded struct {
|
Decoded struct {
|
||||||
Sub string `json:"sub"`
|
Sub string `json:"sub"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
EmailVerified bool `json:"email_verified"`
|
EmailVerified bool `json:"email_verified"`
|
||||||
Sid string `json:"sid"`
|
Sid string `json:"sid"`
|
||||||
Passport struct {
|
Passport struct {
|
||||||
ZkevmEthAddress string `json:"zkevm_eth_address"`
|
ZkevmEthAddress string `json:"zkevm_eth_address"`
|
||||||
} `json:"passport"`
|
} `json:"passport"`
|
||||||
} `json:"decoded"`
|
} `json:"decoded"`
|
||||||
}{}
|
}{}
|
||||||
rspObj := &struct {
|
rspObj := &struct {
|
||||||
ErrCode interface{} `json:"errcode"`
|
ErrCode interface{} `json:"errcode"`
|
||||||
ErrMsg string `json:"errmsg"`
|
ErrMsg string `json:"errmsg"`
|
||||||
}{}
|
}{}
|
||||||
paramsStr := q5.EncodeJson(jsonReqObj)
|
paramsStr := q5.EncodeJson(jsonReqObj)
|
||||||
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Web3ServiceCluster.RandElement().GetUrl())
|
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Web3ServiceCluster.RandElement().GetUrl())
|
||||||
@ -84,19 +100,23 @@ func internalImmutJwtAuth(c *gin.Context, jwtToken string) {
|
|||||||
func(rsp f5.HttpCliResponse) {
|
func(rsp f5.HttpCliResponse) {
|
||||||
if rsp.GetErr() != nil ||
|
if rsp.GetErr() != nil ||
|
||||||
!rsp.JsonParseOk() {
|
!rsp.JsonParseOk() {
|
||||||
rspObj.ErrCode = 500
|
if rsperr {
|
||||||
rspObj.ErrMsg = "server internal error"
|
rspObj.ErrCode = 500
|
||||||
c.JSON(200, rspObj)
|
rspObj.ErrMsg = "server internal error"
|
||||||
c.Abort()
|
c.JSON(200, rspObj)
|
||||||
|
c.Abort()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rspObj.ErrCode = q5.SafeToInt32(jsonRspObj.ErrCode)
|
rspObj.ErrCode = q5.SafeToInt32(jsonRspObj.ErrCode)
|
||||||
rspObj.ErrMsg = jsonRspObj.ErrMsg
|
rspObj.ErrMsg = jsonRspObj.ErrMsg
|
||||||
if q5.SafeToInt32(rspObj.ErrCode) != 0 {
|
if q5.SafeToInt32(rspObj.ErrCode) != 0 {
|
||||||
rspObj.ErrCode = 501
|
if rsperr {
|
||||||
rspObj.ErrMsg = "jwt expired"
|
rspObj.ErrCode = 501
|
||||||
c.JSON(200, rspObj)
|
rspObj.ErrMsg = "jwt expired"
|
||||||
c.Abort()
|
c.JSON(200, rspObj)
|
||||||
|
c.Abort()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
openId := fmt.Sprintf("%d_2006_%s", jccommon.IMTBL_CHANNEL, jsonRspObj.Decoded.Sub)
|
openId := fmt.Sprintf("%d_2006_%s", jccommon.IMTBL_CHANNEL, jsonRspObj.Decoded.Sub)
|
||||||
@ -107,7 +127,7 @@ func internalImmutJwtAuth(c *gin.Context, jwtToken string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func internalMetaMaskJwtAuth(c *gin.Context, jwtToken string) {
|
func internalMetaMaskJwtAuth(c *gin.Context, jwtToken string, rsperr bool) {
|
||||||
params := map[string]string{
|
params := map[string]string{
|
||||||
"c": "MetaMaskJwt",
|
"c": "MetaMaskJwt",
|
||||||
"a": "verify",
|
"a": "verify",
|
||||||
@ -119,18 +139,18 @@ func internalMetaMaskJwtAuth(c *gin.Context, jwtToken string) {
|
|||||||
}
|
}
|
||||||
jsonRspObj := &struct {
|
jsonRspObj := &struct {
|
||||||
ErrCode interface{} `json:"errcode"`
|
ErrCode interface{} `json:"errcode"`
|
||||||
ErrMsg string `json:"errmsg"`
|
ErrMsg string `json:"errmsg"`
|
||||||
Decoded struct {
|
Decoded struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
OpenId string `json:"openid"`
|
OpenId string `json:"openid"`
|
||||||
Plat int32 `json:"plat"`
|
Plat int32 `json:"plat"`
|
||||||
Version int32 `json:"version"`
|
Version int32 `json:"version"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
} `json:"decoded"`
|
} `json:"decoded"`
|
||||||
}{}
|
}{}
|
||||||
rspObj := &struct {
|
rspObj := &struct {
|
||||||
ErrCode interface{} `json:"errcode"`
|
ErrCode interface{} `json:"errcode"`
|
||||||
ErrMsg string `json:"errmsg"`
|
ErrMsg string `json:"errmsg"`
|
||||||
}{}
|
}{}
|
||||||
paramsStr := q5.EncodeJson(jsonReqObj)
|
paramsStr := q5.EncodeJson(jsonReqObj)
|
||||||
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Web3ServiceCluster.RandElement().GetUrl())
|
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Web3ServiceCluster.RandElement().GetUrl())
|
||||||
@ -143,26 +163,32 @@ func internalMetaMaskJwtAuth(c *gin.Context, jwtToken string) {
|
|||||||
func(rsp f5.HttpCliResponse) {
|
func(rsp f5.HttpCliResponse) {
|
||||||
if rsp.GetErr() != nil ||
|
if rsp.GetErr() != nil ||
|
||||||
!rsp.JsonParseOk() {
|
!rsp.JsonParseOk() {
|
||||||
rspObj.ErrCode = 500
|
if rsperr {
|
||||||
rspObj.ErrMsg = "server internal error"
|
rspObj.ErrCode = 500
|
||||||
c.JSON(200, rspObj)
|
rspObj.ErrMsg = "server internal error"
|
||||||
c.Abort()
|
c.JSON(200, rspObj)
|
||||||
|
c.Abort()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rspObj.ErrCode = q5.SafeToInt32(jsonRspObj.ErrCode)
|
rspObj.ErrCode = q5.SafeToInt32(jsonRspObj.ErrCode)
|
||||||
rspObj.ErrMsg = jsonRspObj.ErrMsg
|
rspObj.ErrMsg = jsonRspObj.ErrMsg
|
||||||
if q5.SafeToInt32(rspObj.ErrCode) != 0 {
|
if q5.SafeToInt32(rspObj.ErrCode) != 0 {
|
||||||
rspObj.ErrCode = 501
|
if rsperr {
|
||||||
rspObj.ErrMsg = "jwt error"
|
rspObj.ErrCode = 501
|
||||||
c.JSON(200, rspObj)
|
rspObj.ErrMsg = "jwt error"
|
||||||
c.Abort()
|
c.JSON(200, rspObj)
|
||||||
|
c.Abort()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if jsonRspObj.Decoded.Plat != jccommon.BC_POLY_POLY_METAKASK {
|
if jsonRspObj.Decoded.Plat != jccommon.BC_POLY_POLY_METAKASK {
|
||||||
rspObj.ErrCode = 501
|
if rsperr {
|
||||||
rspObj.ErrMsg = "not support this platform"
|
rspObj.ErrCode = 501
|
||||||
c.JSON(200, rspObj)
|
rspObj.ErrMsg = "not support this platform"
|
||||||
c.Abort()
|
c.JSON(200, rspObj)
|
||||||
|
c.Abort()
|
||||||
|
}
|
||||||
f5.GetSysLog().Info("not support this platform:%s", rsp.GetRawData())
|
f5.GetSysLog().Info("not support this platform:%s", rsp.GetRawData())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user