refactor(auth): simplify admin session token flow

This commit is contained in:
mlogclub
2026-04-30 17:42:24 +08:00
parent e763a75f78
commit fbafb13a8a
12 changed files with 411 additions and 179 deletions
+1 -2
View File
@@ -55,8 +55,7 @@ type LoggerConfig struct {
}
type AuthConfig struct {
AccessTokenTTLHours int `yaml:"accessTokenTTLHours"`
RefreshTokenTTLDays int `yaml:"refreshTokenTTLDays"`
TokenTTLHours int `yaml:"tokenTTLHours"`
MaxFailedAttempts int `yaml:"maxFailedAttempts"`
CredentialLockMinute int `yaml:"credentialLockMinute"`
}
+1 -7
View File
@@ -8,13 +8,7 @@ const (
)
const (
AccessTokenPrefix = "atk_"
RefreshTokenPrefix = "rtk_"
)
const (
TokenTypeAccess = "access"
TokenTypeRefresh = "refresh"
AuthTokenPrefix = "ak_"
)
const (
-8
View File
@@ -5,14 +5,6 @@ type LoginRequest struct {
Password string `json:"password"`
}
type RefreshTokenRequest struct {
RefreshToken string `json:"refreshToken"`
}
type LogoutRequest struct {
RefreshToken string `json:"refreshToken"`
}
type WxWorkExchangeRequest struct {
Ticket string `json:"ticket"`
}
+3 -4
View File
@@ -47,12 +47,11 @@ type CreateUserResultResponse struct {
type SessionResponse struct {
ID int64 `json:"id"`
UserID int64 `json:"userId"`
Username string `json:"username,omitempty"`
TokenType string `json:"tokenType"`
Username string `json:"username"`
ClientType string `json:"clientType"`
ClientIP string `json:"clientIp"`
UserAgent string `json:"userAgent"`
ExpiredAt string `json:"expiredAt"`
RevokedAt string `json:"revokedAt,omitempty"`
LastSeenAt string `json:"lastSeenAt,omitempty"`
RevokedAt string `json:"revokedAt"`
LastSeenAt string `json:"lastSeenAt"`
}
+5 -6
View File
@@ -12,10 +12,9 @@ type AuthUserResponse struct {
}
type LoginResponse struct {
AccessToken string `json:"accessToken"`
RefreshToken string `json:"refreshToken"`
ExpiresAt string `json:"expiresAt"`
User *AuthUserResponse `json:"user"`
Permissions []string `json:"permissions"`
Roles []string `json:"roles"`
AccessToken string `json:"accessToken"`
ExpiresAt string `json:"expiresAt"`
User *AuthUserResponse `json:"user"`
Permissions []string `json:"permissions"`
Roles []string `json:"roles"`
}
+11 -6
View File
@@ -3,12 +3,13 @@ package errorsx
import "github.com/mlogclub/simple/web"
const (
CodeInvalidParam = 1000
CodeBusinessError = 2000
CodeAuthUnauthorized = 3000
CodeAuthForbidden = 3001
CodeAuthInvalidToken = 3002
CodeAuthInvalidAccount = 3003
CodeInvalidParam = 1000
CodeBusinessError = 2000
CodeAuthUnauthorized = 3000
CodeAuthForbidden = 3001
CodeAuthInvalidToken = 3002
CodeAuthInvalidAccount = 3003
CodeAuthCredentialLocked = 3004
)
func InvalidParam(message string) error {
@@ -34,3 +35,7 @@ func InvalidToken(message string) error {
func InvalidAccount(message string) error {
return web.NewError(CodeAuthInvalidAccount, message)
}
func CredentialLocked(message string) error {
return web.NewError(CodeAuthCredentialLocked, message)
}