2026-04-09 10:01:23 +08:00
|
|
|
package irisx
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cs-agent/internal/pkg/openidentity"
|
|
|
|
|
|
|
|
|
|
"github.com/kataras/iris/v12"
|
2026-04-25 10:27:43 +08:00
|
|
|
"github.com/mlogclub/simple/common/strs"
|
|
|
|
|
"github.com/mlogclub/simple/web/params"
|
2026-04-09 10:01:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
2026-04-28 11:10:47 +08:00
|
|
|
ctxKeyExternalUser = "externalUser"
|
2026-04-09 10:01:23 +08:00
|
|
|
)
|
|
|
|
|
|
2026-04-28 11:10:47 +08:00
|
|
|
func SetExternalUser(ctx iris.Context, ext *openidentity.ExternalUser) {
|
|
|
|
|
ctx.Values().Set(ctxKeyExternalUser, ext)
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-28 11:10:47 +08:00
|
|
|
func GetExternalUser(ctx iris.Context) *openidentity.ExternalUser {
|
|
|
|
|
v := ctx.Values().Get(ctxKeyExternalUser)
|
|
|
|
|
ext, _ := v.(*openidentity.ExternalUser)
|
2026-04-09 10:01:23 +08:00
|
|
|
return ext
|
|
|
|
|
}
|
2026-04-25 10:27:43 +08:00
|
|
|
|
|
|
|
|
func GetChannelID(ctx iris.Context) string {
|
|
|
|
|
if channelID := ctx.GetHeader("X-Channel-ID"); strs.IsNotBlank(channelID) {
|
|
|
|
|
return channelID
|
|
|
|
|
}
|
|
|
|
|
if channelID, _ := params.Get(ctx, "channelId"); strs.IsNotBlank(channelID) {
|
|
|
|
|
return channelID
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|