refactor(auth): simplify admin session token flow
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -8,13 +8,7 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
AccessTokenPrefix = "atk_"
|
||||
RefreshTokenPrefix = "rtk_"
|
||||
)
|
||||
|
||||
const (
|
||||
TokenTypeAccess = "access"
|
||||
TokenTypeRefresh = "refresh"
|
||||
AuthTokenPrefix = "ak_"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user