Documentation
¶
Index ¶
- Constants
- Variables
- type ActivateRequest
- type AssignRolePermissionsRequest
- type AssignRolesRequest
- type Authenticator
- type ErrorBody
- type HTTPServer
- func (s *HTTPServer) AuthMiddleware() gin.HandlerFunc
- func (s *HTTPServer) Engine() *gin.Engine
- func (s *HTTPServer) Handler() http.Handler
- func (s *HTTPServer) ParseToken(token string) (*TokenClaims, error)
- func (s *HTTPServer) RequirePermissions(permissions ...string) gin.HandlerFunc
- func (s *HTTPServer) RequireRoles(roles ...string) gin.HandlerFunc
- func (s *HTTPServer) RevokeToken(token string) error
- func (s *HTTPServer) Run(addr string) error
- func (s *HTTPServer) Serve(listener net.Listener) error
- func (s *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type InitSDBPasswordRequest
- type IssuedToken
- type LoginRequest
- type LoginResponse
- type Option
- func WithActivatePath(path string) Option
- func WithAssignRolePath(path string) Option
- func WithAssignRolePermissionPath(path string) Option
- func WithAuthenticator(authenticator Authenticator) Option
- func WithDeactivatePath(path string) Option
- func WithInitPassword(password string) Option
- func WithInitPasswordRotator(rotator func() (string, error)) Option
- func WithInitSDBPasswordPath(path string) Option
- func WithLoginPath(path string) Option
- func WithLogoutPath(path string) Option
- func WithRefreshPath(path string) Option
- func WithRegisterPath(path string) Option
- func WithSQLAllowedOps(ops []string) Option
- func WithSQLExecutePath(path string) Option
- func WithSQLGrantPath(path string) Option
- func WithSQLRevokePath(path string) Option
- func WithTokenRateLimit(enabled bool, requests int, window time.Duration, noTokenPaths []string) Option
- func WithTokenSecret(secret string) Option
- func WithTokenTTL(ttl time.Duration) Option
- type RegisterRequest
- type SQLExecuteRequest
- type SQLExecuteResponse
- type SQLGrantRequest
- type SQLGrantResponse
- type TokenClaims
- type TokenManager
- type TokenResponse
Constants ¶
View Source
const ContextUserKey = "simpledb.transport.user"
View Source
const DefaultActivatePath = "/auth/activate"
View Source
const DefaultAssignRolePermissionsPath = "/auth/assign-role-permissions"
View Source
const DefaultAssignRolesPath = "/auth/assign-roles"
View Source
const DefaultDeactivatePath = "/auth/deactivate"
View Source
const DefaultInitSDBPasswordPath = "/auth/init-sdb-password"
View Source
const DefaultLoginPath = "/auth/login"
View Source
const DefaultLogoutPath = "/auth/logout"
View Source
const DefaultRefreshPath = "/auth/refresh"
View Source
const DefaultRegisterPath = "/auth/register"
View Source
const DefaultSQLExecutePath = "/sql/execute"
View Source
const DefaultSQLGrantPath = "/sql/grant"
View Source
const DefaultSQLRevokePath = "/sql/revoke"
View Source
const SuperAdminRoleCode = "super_admin"
Variables ¶
View Source
var ( ErrInvalidToken = errors.New("invalid token") ErrExpiredToken = errors.New("expired token") )
View Source
var New app
Functions ¶
This section is empty.
Types ¶
type ActivateRequest ¶
type ActivateRequest struct {
Username string `json:"username"`
}
type AssignRolesRequest ¶
type Authenticator ¶
type Authenticator interface {
Authenticate(database, username, password string) (*driver.AuthenticatedUser, error)
RegisterUser(database, username, password, displayName string) (*driver.AuthenticatedUser, error)
ActivateUser(database, username string) (*driver.AuthenticatedUser, error)
DeactivateUser(database, username string) (*driver.AuthenticatedUser, error)
AssignRoles(database, username string, roleCodes []string) (*driver.AuthenticatedUser, error)
AssignRolePermissions(database, roleCode string, permissionCodes []string) error
InitSDBPassword(database string) error
BindUserDatabase(database string, approver *driver.AuthenticatedUser, username string) error
RevokeUserDatabase(database string, approver *driver.AuthenticatedUser, username string) error
}
type HTTPServer ¶
type HTTPServer struct {
Database string
LoginPath string
RegisterPath string
RefreshPath string
LogoutPath string
ActivatePath string
DeactivatePath string
AssignRolePath string
AssignRolePermissionPath string
InitSDBPasswordPath string
SQLExecutePath string
SQLGrantPath string
SQLRevokePath string
SQLAllowedOps map[string]struct{} // nil = 不限制
LimitEnabled bool
LimitRequests int
LimitWindow time.Duration
LimitNoTokenPaths map[string]struct{}
InitPassword string
TokenTTL time.Duration
TokenSecret string
// contains filtered or unexported fields
}
func (*HTTPServer) AuthMiddleware ¶
func (s *HTTPServer) AuthMiddleware() gin.HandlerFunc
func (*HTTPServer) Engine ¶
func (s *HTTPServer) Engine() *gin.Engine
func (*HTTPServer) Handler ¶
func (s *HTTPServer) Handler() http.Handler
func (*HTTPServer) ParseToken ¶
func (s *HTTPServer) ParseToken(token string) (*TokenClaims, error)
func (*HTTPServer) RequirePermissions ¶
func (s *HTTPServer) RequirePermissions(permissions ...string) gin.HandlerFunc
func (*HTTPServer) RequireRoles ¶
func (s *HTTPServer) RequireRoles(roles ...string) gin.HandlerFunc
func (*HTTPServer) RevokeToken ¶
func (s *HTTPServer) RevokeToken(token string) error
func (*HTTPServer) Run ¶
func (s *HTTPServer) Run(addr string) error
func (*HTTPServer) ServeHTTP ¶
func (s *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
type InitSDBPasswordRequest ¶
type InitSDBPasswordRequest struct {
Password string `json:"password"`
}
type IssuedToken ¶
type LoginRequest ¶
type LoginResponse ¶
type LoginResponse struct {
Success bool `json:"success"`
User *driver.AuthenticatedUser `json:"user,omitempty"`
Token *TokenResponse `json:"token,omitempty"`
Error *ErrorBody `json:"error,omitempty"`
}
type Option ¶
type Option func(*HTTPServer)
func WithActivatePath ¶
func WithAssignRolePath ¶
func WithAuthenticator ¶
func WithAuthenticator(authenticator Authenticator) Option
func WithDeactivatePath ¶
func WithInitPassword ¶
func WithInitPasswordRotator ¶
func WithInitSDBPasswordPath ¶
func WithLoginPath ¶
func WithLogoutPath ¶
func WithRefreshPath ¶
func WithRegisterPath ¶
func WithSQLAllowedOps ¶
func WithSQLExecutePath ¶
func WithSQLGrantPath ¶
func WithSQLRevokePath ¶
func WithTokenRateLimit ¶
func WithTokenSecret ¶
func WithTokenTTL ¶
type RegisterRequest ¶
type SQLExecuteRequest ¶
type SQLExecuteResponse ¶
type SQLExecuteResponse struct {
Success bool `json:"success"`
Result *api.ExecResult `json:"result,omitempty"`
Error *ErrorBody `json:"error,omitempty"`
}
type SQLGrantRequest ¶
type SQLGrantRequest struct {
Database string `json:"database,omitempty"`
Username string `json:"username,omitempty"`
// legacy aliases
Table string `json:"table,omitempty"`
Grantee string `json:"grantee,omitempty"`
}
SQLGrantRequest is the request body for POST /sql/grant.
type SQLGrantResponse ¶
type SQLGrantResponse struct {
Success bool `json:"success"`
Error *ErrorBody `json:"error,omitempty"`
}
SQLGrantResponse is the response body for POST /sql/grant.
type TokenClaims ¶
type TokenClaims struct {
TokenID string `json:"jti"`
Subject string `json:"sub"`
Username string `json:"username"`
DisplayName string `json:"displayName,omitempty"`
Status string `json:"status,omitempty"`
IsAdmin bool `json:"isAdmin"`
Roles []string `json:"roles,omitempty"`
Permissions []string `json:"permissions,omitempty"`
IssuedAt int64 `json:"iat"`
ExpiresAt int64 `json:"exp"`
}
func UserFromContext ¶
func UserFromContext(ctx *gin.Context) (*TokenClaims, bool)
type TokenManager ¶
type TokenManager struct {
// contains filtered or unexported fields
}
func NewTokenManager ¶
func NewTokenManager(database, secret string, ttl time.Duration) *TokenManager
func (*TokenManager) Issue ¶
func (m *TokenManager) Issue(user *driver.AuthenticatedUser) (*IssuedToken, error)
func (*TokenManager) Parse ¶
func (m *TokenManager) Parse(token string) (*TokenClaims, error)
func (*TokenManager) Refresh ¶
func (m *TokenManager) Refresh(token string) (*IssuedToken, *TokenClaims, error)
func (*TokenManager) Revoke ¶
func (m *TokenManager) Revoke(token string) error
type TokenResponse ¶
Click to show internal directories.
Click to hide internal directories.