feat: rebind mobile
This commit is contained in:
@@ -33,12 +33,17 @@ const (
|
||||
CtxGroupId ctxKey = "X-Group-Id"
|
||||
CtxGroupName ctxKey = "X-Group-Name"
|
||||
CtxUserType ctxKey = "X-User-Type"
|
||||
CtxBizId ctxKey = "X-Biz-Id"
|
||||
CtxRawBody ctxKey = "X-Raw-Body"
|
||||
CtxBizId ctxKey = "X-Biz-Id"
|
||||
CtxRawBody ctxKey = "X-Raw-Body"
|
||||
CtxOssAuth ctxKey = "X-Oss-Authorization"
|
||||
CtxOssPubKeyURL ctxKey = "X-Oss-Pub-Key-Url"
|
||||
CtxRequestPath ctxKey = "X-Request-Path"
|
||||
CtxRequestQuery ctxKey = "X-Request-Query"
|
||||
)
|
||||
|
||||
var callbackPrefixes = []string{
|
||||
"/api/v3/express/",
|
||||
"/api/v1/oss/callback",
|
||||
"/api/v3/other1/",
|
||||
"/api/v3/other2/",
|
||||
}
|
||||
@@ -60,9 +65,13 @@ type UserInfo struct {
|
||||
StoreName string
|
||||
GroupId string
|
||||
GroupName string
|
||||
BizId string
|
||||
RawBody string
|
||||
Valid bool
|
||||
BizId string
|
||||
RawBody string
|
||||
OssAuth string
|
||||
OssPubKeyURL string
|
||||
RequestPath string
|
||||
RequestQuery string
|
||||
Valid bool
|
||||
}
|
||||
|
||||
func GetUserInfo(ctx context.Context) UserInfo {
|
||||
@@ -83,6 +92,10 @@ func GetUserInfo(ctx context.Context) UserInfo {
|
||||
groupName, _ := ctx.Value(CtxGroupName).(string)
|
||||
bizId, _ := ctx.Value(CtxBizId).(string)
|
||||
rawBody, _ := ctx.Value(CtxRawBody).(string)
|
||||
ossAuth, _ := ctx.Value(CtxOssAuth).(string)
|
||||
ossPubKeyURL, _ := ctx.Value(CtxOssPubKeyURL).(string)
|
||||
requestPath, _ := ctx.Value(CtxRequestPath).(string)
|
||||
requestQuery, _ := ctx.Value(CtxRequestQuery).(string)
|
||||
|
||||
info := UserInfo{
|
||||
RawUID: rawUID,
|
||||
@@ -102,6 +115,10 @@ func GetUserInfo(ctx context.Context) UserInfo {
|
||||
GroupName: groupName,
|
||||
BizId: bizId,
|
||||
RawBody: rawBody,
|
||||
OssAuth: ossAuth,
|
||||
OssPubKeyURL: ossPubKeyURL,
|
||||
RequestPath: requestPath,
|
||||
RequestQuery: requestQuery,
|
||||
}
|
||||
if rawUID == "" {
|
||||
return info
|
||||
@@ -156,6 +173,12 @@ func UserReadMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
||||
newCtx = context.WithValue(newCtx, CtxGroupId, r.Header.Get("X-Group-Id"))
|
||||
newCtx = context.WithValue(newCtx, CtxGroupName, r.Header.Get("X-Group-Name"))
|
||||
newCtx = context.WithValue(newCtx, CtxBizId, r.Header.Get("X-Biz-Id"))
|
||||
if isCallbackPath(r.URL.Path) {
|
||||
newCtx = context.WithValue(newCtx, CtxOssAuth, r.Header.Get("Authorization"))
|
||||
newCtx = context.WithValue(newCtx, CtxOssPubKeyURL, r.Header.Get("X-Oss-Pub-Key-Url"))
|
||||
newCtx = context.WithValue(newCtx, CtxRequestPath, r.URL.Path)
|
||||
newCtx = context.WithValue(newCtx, CtxRequestQuery, r.URL.RawQuery)
|
||||
}
|
||||
next(w, r.WithContext(newCtx))
|
||||
}
|
||||
}
|
||||
@@ -207,6 +230,10 @@ func UserClientInterceptor(ctx context.Context, method string, req, reply any, c
|
||||
md.Set("x-group-name", url.QueryEscape(user.GroupName))
|
||||
}
|
||||
setMDIfNotEmpty(md, "x-biz-id", user.BizId)
|
||||
setMDIfNotEmpty(md, "x-oss-authorization", user.OssAuth)
|
||||
setMDIfNotEmpty(md, "x-oss-pub-key-url", user.OssPubKeyURL)
|
||||
setMDIfNotEmpty(md, "x-request-path", user.RequestPath)
|
||||
setMDIfNotEmpty(md, "x-request-query", user.RequestQuery)
|
||||
|
||||
ctx = metadata.NewOutgoingContext(ctx, md)
|
||||
return invoker(ctx, method, req, reply, cc, opts...)
|
||||
@@ -245,6 +272,10 @@ func UserStreamInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.
|
||||
md.Set("x-group-name", url.QueryEscape(user.GroupName))
|
||||
}
|
||||
setMDIfNotEmpty(md, "x-biz-id", user.BizId)
|
||||
setMDIfNotEmpty(md, "x-oss-authorization", user.OssAuth)
|
||||
setMDIfNotEmpty(md, "x-oss-pub-key-url", user.OssPubKeyURL)
|
||||
setMDIfNotEmpty(md, "x-request-path", user.RequestPath)
|
||||
setMDIfNotEmpty(md, "x-request-query", user.RequestQuery)
|
||||
|
||||
newCtx := metadata.NewOutgoingContext(ctx, md)
|
||||
return streamer(newCtx, desc, cc, method, opts...)
|
||||
|
||||
Reference in New Issue
Block a user