Documentation
¶
Index ¶
- Constants
- Variables
- func APIAuthorizer(authorizer echox.Authorizer) api.Authorizer
- func Authorizer(authorizer rbac.Authorizer) echox.Authorizer
- func BasicAuthValidator(repo repository.Admin, logger *zap.Logger) middleware.BasicAuthValidator
- func CtxAdmin(ctx context.Context) *model.Admin
- func CtxTwoFA(ctx context.Context) bool
- func GenerateAvatar(isMale bool) string
- func JWTAuthValidator(repo repository.Admin, cfg Config) middleware.KeyAuthValidator
- func NewJWT(payload jwt.MapClaims, signingKey string, exp time.Duration) (string, error)
- func ParseJWT(token string, verificationKey string) (jwt.MapClaims, error)
- func ParseUnverifiedJWT(token string) (jwt.MapClaims, error)
- func WithAdmin(ctx context.Context, a *model.Admin) context.Context
- func WithTwoFA(ctx context.Context, twoFA bool) context.Context
- type Assertion2FA
- type AssertionSuperAdmin
- type AssertionSuperAdminOrOwner
- type AuthService
- type CleanupRefreshTokens
- type Config
- type DefaultAuthService
- func (s *DefaultAuthService) Auth(ctx context.Context, username, password string) (model.Session, error)
- func (s *DefaultAuthService) OTP(ctx context.Context, a model.Admin, password string) (model.Session, error)
- func (s *DefaultAuthService) Refresh(ctx context.Context, token string) (model.Session, error)
- func (s *DefaultAuthService) Session(ctx context.Context, a model.Admin, twoFA bool) (model.Session, error)
- type DefaultService
- func (s *DefaultService) Activate(ctx context.Context, username string) (model.Admin, error)
- func (s *DefaultService) Change(ctx context.Context, username string, fn func(a *model.Admin) (bool, error)) (model.Admin, error)
- func (s *DefaultService) ChangeAvatar(ctx context.Context, username, avatar string) (model.Admin, error)
- func (s *DefaultService) ChangeEmail(ctx context.Context, username, email string) (model.Admin, error)
- func (s *DefaultService) ChangeOTP(ctx context.Context, username string) (model.Admin, error)
- func (s *DefaultService) ChangePassword(ctx context.Context, username, password string) (model.Admin, error)
- func (s *DefaultService) ChangeRoles(ctx context.Context, username string, roles ...string) (model.Admin, error)
- func (s *DefaultService) ChangeUsername(ctx context.Context, oldUsername, newUsername string) (model.Admin, error)
- func (s *DefaultService) Create(ctx context.Context, email, username, password, avatar string, isActive bool, ...) (model.Admin, error)
- func (s *DefaultService) Deactivate(ctx context.Context, username string) (model.Admin, error)
- func (s *DefaultService) Get(ctx context.Context, username string) (model.Admin, error)
- func (s *DefaultService) GetOTPKey(ctx context.Context, username, issuer string) (string, error)
- type Service
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 GenerateAvatar ¶
func JWTAuthValidator ¶
func JWTAuthValidator(repo repository.Admin, cfg Config) middleware.KeyAuthValidator
func ParseUnverifiedJWT ¶
ParseUnverifiedJWT parses JWT and returns its claims but DOES NOT verify the signature.
It verifies only the exp, iat and nbf claims.
Types ¶
type Assertion2FA ¶
type Assertion2FA struct{}
type AssertionSuperAdmin ¶
type AssertionSuperAdmin struct{}
type AssertionSuperAdminOrOwner ¶
type AssertionSuperAdminOrOwner struct{}
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
type DefaultService ¶
type DefaultService struct {
// contains filtered or unexported fields
}
func NewDefaultService ¶
func NewDefaultService(adminRepository repository.Admin, refreshRepository repository.RefreshToken) *DefaultService
func (*DefaultService) ChangeAvatar ¶
func (*DefaultService) ChangeEmail ¶
func (*DefaultService) ChangePassword ¶
func (*DefaultService) ChangeRoles ¶
func (*DefaultService) ChangeUsername ¶
func (*DefaultService) Deactivate ¶
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)
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.