admin

package module
v0.0.0-...-cf98a52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2024 License: MIT Imports: 21 Imported by: 0

README

Admin

Installation

go get -u github.com/gowool/admin

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

View Source
const RoleSuperAdmin = "ROLE_SUPER_ADMIN"

Variables

View Source
var (
	ErrAdminNotActive      = errors.New("admin: is not active")
	ErrRefreshTokenExpired = errors.New("admin: refresh token is expired")
)

Functions

func APIAuthorizer

func APIAuthorizer(authorizer echox.Authorizer) api.Authorizer

func Authorizer

func Authorizer(authorizer rbac.Authorizer) echox.Authorizer

func BasicAuthValidator

func BasicAuthValidator(repo repository.Admin, logger *zap.Logger) middleware.BasicAuthValidator

func CtxAdmin

func CtxAdmin(ctx context.Context) *model.Admin

func CtxTwoFA

func CtxTwoFA(ctx context.Context) bool

func GenerateAvatar

func GenerateAvatar(isMale bool) string

func JWTAuthValidator

func JWTAuthValidator(repo repository.Admin, cfg Config) middleware.KeyAuthValidator

func NewJWT

func NewJWT(payload jwt.MapClaims, signingKey string, exp time.Duration) (string, error)

NewJWT generates and returns new HS256 signed JWT.

func ParseJWT

func ParseJWT(token string, verificationKey string) (jwt.MapClaims, error)

ParseJWT verifies and parses JWT and returns its claims.

func ParseUnverifiedJWT

func ParseUnverifiedJWT(token string) (jwt.MapClaims, error)

ParseUnverifiedJWT parses JWT and returns its claims but DOES NOT verify the signature.

It verifies only the exp, iat and nbf claims.

func WithAdmin

func WithAdmin(ctx context.Context, a *model.Admin) context.Context

func WithTwoFA

func WithTwoFA(ctx context.Context, twoFA bool) context.Context

Types

type Assertion2FA

type Assertion2FA struct{}

func (Assertion2FA) Assert

func (Assertion2FA) Assert(ctx context.Context, _ rbac.Role, _ string) (bool, error)

type AssertionSuperAdmin

type AssertionSuperAdmin struct{}

func (AssertionSuperAdmin) Assert

func (AssertionSuperAdmin) Assert(_ context.Context, role rbac.Role, _ string) (bool, error)

type AssertionSuperAdminOrOwner

type AssertionSuperAdminOrOwner struct{}

func (AssertionSuperAdminOrOwner) Assert

type AuthService

type AuthService interface {
	Auth(ctx context.Context, username, password string) (model.Session, error)
	OTP(ctx context.Context, a model.Admin, password string) (model.Session, error)
	Refresh(ctx context.Context, token string) (model.Session, error)
	Session(ctx context.Context, a model.Admin, twoFA bool) (model.Session, error)
}

type CleanupRefreshTokens

type CleanupRefreshTokens struct {
	// contains filtered or unexported fields
}

func NewCleanupRefreshTokens

func NewCleanupRefreshTokens(config Config, refreshRepository repository.RefreshToken, logger *zap.Logger) *CleanupRefreshTokens

func (*CleanupRefreshTokens) Start

func (c *CleanupRefreshTokens) Start()

func (*CleanupRefreshTokens) Stop

func (c *CleanupRefreshTokens) Stop()

type Config

type Config struct {
	Secret               string        `json:"secret,omitempty" yaml:"secret,omitempty"`
	AccessTokenDuration  time.Duration `json:"accessTokenDuration,omitempty" yaml:"accessTokenDuration,omitempty"`
	RefreshTokenDuration time.Duration `json:"refreshTokenDuration,omitempty" yaml:"refreshTokenDuration,omitempty"`
	CleanupInterval      time.Duration `json:"cleanupInterval,omitempty" yaml:"cleanupInterval,omitempty"`
}

func (*Config) SetDefaults

func (cfg *Config) SetDefaults()

type DefaultAuthService

type DefaultAuthService struct {
	// contains filtered or unexported fields
}

func NewDefaultAuthService

func NewDefaultAuthService(config Config, adminRepository repository.Admin, refreshRepository repository.RefreshToken) *DefaultAuthService

func (*DefaultAuthService) Auth

func (s *DefaultAuthService) Auth(ctx context.Context, username, password string) (model.Session, error)

func (*DefaultAuthService) OTP

func (s *DefaultAuthService) OTP(ctx context.Context, a model.Admin, password string) (model.Session, error)

func (*DefaultAuthService) Refresh

func (s *DefaultAuthService) Refresh(ctx context.Context, token string) (model.Session, error)

func (*DefaultAuthService) Session

func (s *DefaultAuthService) Session(ctx context.Context, a model.Admin, twoFA bool) (model.Session, error)

type DefaultService

type DefaultService struct {
	// contains filtered or unexported fields
}

func NewDefaultService

func NewDefaultService(adminRepository repository.Admin, refreshRepository repository.RefreshToken) *DefaultService

func (*DefaultService) Activate

func (s *DefaultService) Activate(ctx context.Context, username string) (model.Admin, error)

func (*DefaultService) Change

func (s *DefaultService) Change(ctx context.Context, username string, fn func(a *model.Admin) (bool, error)) (model.Admin, error)

func (*DefaultService) ChangeAvatar

func (s *DefaultService) ChangeAvatar(ctx context.Context, username, avatar string) (model.Admin, error)

func (*DefaultService) ChangeEmail

func (s *DefaultService) ChangeEmail(ctx context.Context, username, email string) (model.Admin, error)

func (*DefaultService) ChangeOTP

func (s *DefaultService) ChangeOTP(ctx context.Context, username string) (model.Admin, error)

func (*DefaultService) ChangePassword

func (s *DefaultService) ChangePassword(ctx context.Context, username, password string) (model.Admin, error)

func (*DefaultService) ChangeRoles

func (s *DefaultService) ChangeRoles(ctx context.Context, username string, roles ...string) (model.Admin, error)

func (*DefaultService) ChangeUsername

func (s *DefaultService) ChangeUsername(ctx context.Context, oldUsername, newUsername string) (model.Admin, error)

func (*DefaultService) Create

func (s *DefaultService) Create(ctx context.Context, email, username, password, avatar string, isActive bool, roles ...string) (model.Admin, error)

func (*DefaultService) Deactivate

func (s *DefaultService) Deactivate(ctx context.Context, username string) (model.Admin, error)

func (*DefaultService) Get

func (s *DefaultService) Get(ctx context.Context, username string) (model.Admin, error)

func (*DefaultService) GetOTPKey

func (s *DefaultService) GetOTPKey(ctx context.Context, username, issuer string) (string, error)

type Service

type Service interface {
	Get(ctx context.Context, username string) (model.Admin, error)
	GetOTPKey(ctx context.Context, username, issuer string) (string, error)
	Create(ctx context.Context, email, username, password, avatar string, isActive bool, roles ...string) (model.Admin, error)
	Change(ctx context.Context, username string, fn func(a *model.Admin) (bool, error)) (model.Admin, error)
	ChangeAvatar(ctx context.Context, username, avatar string) (model.Admin, error)
	ChangeEmail(ctx context.Context, username, email string) (model.Admin, error)
	ChangeUsername(ctx context.Context, oldUsername, newUsername string) (model.Admin, error)
	ChangePassword(ctx context.Context, username, password string) (model.Admin, error)
	ChangeRoles(ctx context.Context, username string, roles ...string) (model.Admin, error)
	ChangeOTP(ctx context.Context, username string) (model.Admin, error)
	Activate(ctx context.Context, username string) (model.Admin, error)
	Deactivate(ctx context.Context, username string) (model.Admin, error)
}

Directories

Path Synopsis
api
v1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL