重构增加模型枚举值定义
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"log/slog"
|
||||
client2 "platform/web/domains/client"
|
||||
q "platform/web/queries"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -38,7 +39,7 @@ func Protect(c *fiber.Ctx, types []PayloadType, permissions []string) (*Context,
|
||||
}
|
||||
|
||||
case "Basic":
|
||||
if !slices.Contains(types, PayloadClientConfidential) {
|
||||
if !slices.Contains(types, PayloadSecuredServer) {
|
||||
slog.Debug("禁止使用 Basic 认证方式")
|
||||
return nil, fiber.NewError(fiber.StatusUnauthorized, "无效的令牌")
|
||||
}
|
||||
@@ -106,7 +107,7 @@ func authBasic(_ context.Context, token string) (*Context, error) {
|
||||
client, err := q.Client.
|
||||
Where(
|
||||
q.Client.ClientID.Eq(clientID),
|
||||
q.Client.Spec.Eq(3),
|
||||
q.Client.Spec.In(int32(client2.SpecWeb), int32(client2.SpecTrusted)),
|
||||
q.Client.GrantClient.Is(true),
|
||||
q.Client.Status.Eq(1)).
|
||||
Take()
|
||||
@@ -126,7 +127,7 @@ func authBasic(_ context.Context, token string) (*Context, error) {
|
||||
return &Context{
|
||||
Payload: Payload{
|
||||
Id: client.ID,
|
||||
Type: PayloadClientConfidential,
|
||||
Type: PayloadSecuredServer,
|
||||
Name: client.Name,
|
||||
Avatar: client.Icon,
|
||||
},
|
||||
|
||||
@@ -37,15 +37,18 @@ type Agent struct {
|
||||
type PayloadType int
|
||||
|
||||
const (
|
||||
// PayloadNone 游客
|
||||
PayloadNone PayloadType = iota
|
||||
// PayloadUser 用户类型
|
||||
// PayloadUser 用户
|
||||
PayloadUser
|
||||
// PayloadAdmin 管理员类型
|
||||
// PayloadAdmin 管理员
|
||||
PayloadAdmin
|
||||
// PayloadClientPublic 公共客户端类型
|
||||
PayloadClientPublic
|
||||
// PayloadClientConfidential 机密客户端类型
|
||||
PayloadClientConfidential
|
||||
// PayloadPublicServer 公共服务(public_client)
|
||||
PayloadPublicServer
|
||||
// PayloadSecuredServer 安全服务(credential_client)
|
||||
PayloadSecuredServer
|
||||
// PayloadInternalServer 内部服务
|
||||
PayloadInternalServer
|
||||
)
|
||||
|
||||
func (t PayloadType) ToStr() string {
|
||||
@@ -54,9 +57,9 @@ func (t PayloadType) ToStr() string {
|
||||
return "user"
|
||||
case PayloadAdmin:
|
||||
return "admn"
|
||||
case PayloadClientPublic:
|
||||
case PayloadPublicServer:
|
||||
return "cpub"
|
||||
case PayloadClientConfidential:
|
||||
case PayloadSecuredServer:
|
||||
return "ccnf"
|
||||
default:
|
||||
return "none"
|
||||
@@ -70,9 +73,9 @@ func PayloadTypeFromStr(name string) PayloadType {
|
||||
case "admn":
|
||||
return PayloadAdmin
|
||||
case "cpub":
|
||||
return PayloadClientPublic
|
||||
return PayloadPublicServer
|
||||
case "ccnf":
|
||||
return PayloadClientConfidential
|
||||
return PayloadSecuredServer
|
||||
default:
|
||||
return PayloadNone
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user