重构迁移核心数据结构到认证模块;完善中间件初始化逻辑以及 logger 记录过程

This commit is contained in:
2025-05-08 13:18:54 +08:00
parent c93d0bf467
commit e2cc318560
24 changed files with 353 additions and 215 deletions

View File

@@ -3,6 +3,7 @@ package services
import (
"context"
"errors"
"platform/web/auth"
"platform/web/core"
m "platform/web/models"
q "platform/web/queries"
@@ -24,14 +25,14 @@ func (s *authService) OauthAuthorizationCode(ctx context.Context, client *m.Clie
// OauthClientCredentials 验证客户端凭证
func (s *authService) OauthClientCredentials(ctx context.Context, client *m.Client, scope ...string) (*TokenDetails, error) {
var clientType PayloadType
var clientType auth.PayloadType
switch client.Spec {
case 1:
clientType = PayloadClientPublic
clientType = auth.PayloadClientPublic
case 2:
clientType = PayloadClientPublic
clientType = auth.PayloadClientPublic
case 3:
clientType = PayloadClientConfidential
clientType = auth.PayloadClientConfidential
}
var permissions = make(map[string]struct{}, len(scope))
@@ -40,9 +41,9 @@ func (s *authService) OauthClientCredentials(ctx context.Context, client *m.Clie
}
// 保存会话并返回令牌
auth := AuthContext{
authCtx := auth.Context{
Permissions: permissions,
Payload: Payload{
Payload: auth.Payload{
Id: client.ID,
Type: clientType,
Name: client.Name,
@@ -50,7 +51,7 @@ func (s *authService) OauthClientCredentials(ctx context.Context, client *m.Clie
}
// todo 数据库定义会话持续时间
token, err := Session.Create(ctx, auth, false)
token, err := Session.Create(ctx, authCtx, false)
if err != nil {
return nil, err
}
@@ -136,16 +137,16 @@ func (s *authService) OauthPassword(ctx context.Context, _ *m.Client, data *Gran
}
// 保存到会话
auth := AuthContext{
Payload: Payload{
authCtx := auth.Context{
Payload: auth.Payload{
Id: user.ID,
Type: PayloadUser,
Type: auth.PayloadUser,
Name: user.Name,
Avatar: user.Avatar,
},
}
token, err := Session.Create(ctx, auth, data.Remember)
token, err := Session.Create(ctx, authCtx, data.Remember)
if err != nil {
return nil, err
}