auth

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authenticator

type Authenticator struct {
	Config       config.AuthConfig
	AuthStore    IStoreWrapper
	Validator    IAuthValidator
	SessionStore IAuthSessionStore
}

func NewAuthenticator

func NewAuthenticator(config config.AuthConfig, validator IAuthValidator, authstore IStoreWrapper, sessionstore IAuthSessionStore) *Authenticator

func (*Authenticator) Check

func (a *Authenticator) Check(ctx *fiber.Ctx) error

func (*Authenticator) GetLoginRequest added in v0.0.24

func (a *Authenticator) GetLoginRequest(ctx *fiber.Ctx) (string, string, error)

func (*Authenticator) GetRefreshTokenRequest added in v0.0.24

func (a *Authenticator) GetRefreshTokenRequest(ctx *fiber.Ctx) (string, error)

func (*Authenticator) Login added in v0.0.24

func (a *Authenticator) Login(ctx *fiber.Ctx) (*UserLoginInfo, error)

func (*Authenticator) Logout added in v0.0.24

func (a *Authenticator) Logout(ctx *fiber.Ctx) error

func (*Authenticator) RefreshToken added in v0.0.24

func (a *Authenticator) RefreshToken(ctx *fiber.Ctx) (*UserLoginInfo, error)

type Authorization

type Authorization struct {
	Loader IStoreWrapper
}

func NewAuthorization

func NewAuthorization(loader IStoreWrapper) (*Authorization, error)

func (*Authorization) Check

func (a *Authorization) Check(user IUserAuthInfo, method string, path string) error

type ConditionABAC

type ConditionABAC struct {
	Attribute string
	Operator  string
	Value     any
}

type IAuthSession added in v0.0.24

type IAuthSession interface {
	SetSessionStore(session ISessionStore)
	Login(ctx *fiber.Ctx, userInfo IUserAuthInfo) (*UserLoginInfo, error)
	Refresh(ctx *fiber.Ctx, userKey string) (*UserLoginInfo, error)
	Logout(ctx *fiber.Ctx, userKey string) error
}

type IAuthSessionStore added in v0.0.24

type IAuthSessionStore interface {
	GetSessionStore() ISessionStore
}

type IAuthStore

type IAuthStore interface {
	GetStore() IStore
}

type IAuthValidator

type IAuthValidator interface {
	Name() string
	GetValue() string
	ValidateKey(ctx *fiber.Ctx) error
	VerifyUser(ctx *fiber.Ctx, userKey string, userInfo IUserAuthInfo) (bool, error)
	IsRequireLogin() bool
	GetAuthSession() IAuthSession
}

type IAuthenticationManager

type IAuthenticationManager interface {
	GetAuthenticatonHandler() fiber.Handler
}

type IAuthorization

type IAuthorization interface {
	port.Library

	Check(user IUserAuthInfo, method string, path string) error
}

type IAuthorizationManager

type IAuthorizationManager interface {
	GetAuthorization() IAuthorization
}

type IResourceInfo

type IResourceInfo interface {
	GetAction() string
	GetMethod() string
	GetPath() string
	GetControlType() string // 'RBAC' or 'ABAC'
	IsUserPermitted(user IUserAuthInfo) error
}

type ISessionStore added in v0.0.24

type ISessionStore interface {
	Save(loginInfo *UserLoginInfo) error
	Refresh(oldAccessToken string, loginInfo *UserLoginInfo) error
	Delete(loginInfo *UserLoginInfo) error
	GetByAccessToken(accessToken string) (*UserLoginInfo, error)
	GetByRefreshToken(refreshToken string) (*UserLoginInfo, error)
	GetByUsername(username string) (*UserLoginInfo, error)
}

type IStore

type IStore interface {
	GetUserLoginInfo(ctx *fiber.Ctx, username string, password string) (IUserAuthInfo, error) // digunakan saat login
	GetUserAuthInfo(ctx *fiber.Ctx, validator IAuthValidator) (IUserAuthInfo, error)          // digunakan untuk verifikasi userkey
	GetResourceInfo(method string, path string) (IResourceInfo, error)
}

type IStoreWrapper

type IStoreWrapper interface {
	CheckUser(ctx *fiber.Ctx, validator IAuthValidator) error
	GetLoadedUser() IUserAuthInfo

	CheckResource(method string, path string) (bool, error)
	GetLoadedResource() IResourceInfo
}

type IUserAuthInfo

type IUserAuthInfo interface {
	GetControlType() string // 'RBAC' or 'ABAC'
}

type PolicyABAC

type PolicyABAC struct {
	Effect    string // 'Allow' or 'Deny'
	Action    string
	Condition []ConditionABAC // condition with 'AND' operator (Nested and OR operation not supported yet)
}

type ResourceInfoABAC

type ResourceInfoABAC struct {
	Action            string       `mapstructure:"action"`
	Path              string       `mapstructure:"path"`
	Method            string       `mapstructure:"method"`
	PermittedPolicies []PolicyABAC `mapstructure:"policies"`
}

func (*ResourceInfoABAC) GetAction

func (r2 *ResourceInfoABAC) GetAction() string

func (*ResourceInfoABAC) GetControlType

func (r2 *ResourceInfoABAC) GetControlType() string

func (*ResourceInfoABAC) GetMethod

func (r2 *ResourceInfoABAC) GetMethod() string

func (*ResourceInfoABAC) GetPath

func (r2 *ResourceInfoABAC) GetPath() string

func (*ResourceInfoABAC) IsAccessGranted

func (r2 *ResourceInfoABAC) IsAccessGranted(userPolicy PolicyABAC, policies []PolicyABAC) bool

func (*ResourceInfoABAC) IsUserPermitted

func (r2 *ResourceInfoABAC) IsUserPermitted(user IUserAuthInfo) error

type ResourceInfoRBAC

type ResourceInfoRBAC struct {
	Action         string   `mapstructure:"action"`
	Path           string   `mapstructure:"path"`
	Method         string   `mapstructure:"method"`
	PermittedRoles []string `mapstructure:"permissions"`
}

func (*ResourceInfoRBAC) GetAction

func (r1 *ResourceInfoRBAC) GetAction() string

func (*ResourceInfoRBAC) GetControlType

func (r1 *ResourceInfoRBAC) GetControlType() string

func (*ResourceInfoRBAC) GetMethod

func (r1 *ResourceInfoRBAC) GetMethod() string

func (*ResourceInfoRBAC) GetPath

func (r1 *ResourceInfoRBAC) GetPath() string

func (*ResourceInfoRBAC) IsUserPermitted

func (r1 *ResourceInfoRBAC) IsUserPermitted(user IUserAuthInfo) error

type StoreWrapper

type StoreWrapper struct {
	Store    IStore
	User     IUserAuthInfo
	Resource IResourceInfo
}

func NewStoreWrapper

func NewStoreWrapper(store IStore) *StoreWrapper

func (*StoreWrapper) CheckResource

func (u *StoreWrapper) CheckResource(method string, path string) (bool, error)

func (*StoreWrapper) CheckUser

func (u *StoreWrapper) CheckUser(ctx *fiber.Ctx, validator IAuthValidator) error

func (*StoreWrapper) GetLoadedResource

func (u *StoreWrapper) GetLoadedResource() IResourceInfo

func (*StoreWrapper) GetLoadedUser

func (u *StoreWrapper) GetLoadedUser() IUserAuthInfo

type UserAuthInfo

type UserAuthInfo struct {
}

type UserAuthInfoABAC

type UserAuthInfoABAC struct {
	UserAuthInfo
	UserId   string       `mapstructure:"key"`      // used by Api Key and JWT
	Username *string      `mapstructure:"user"`     // used by Basic Auth
	Password *string      `mapstructure:"password"` // used by Basic Auth
	Groups   []string     `mapstructure:"groups"`   // used by JWT Auth
	Policies []PolicyABAC `mapstructure:"policies"`
}

func (*UserAuthInfoABAC) GetControlType

func (u2 *UserAuthInfoABAC) GetControlType() string

func (*UserAuthInfoABAC) GetUserID

func (u2 *UserAuthInfoABAC) GetUserID() string

type UserAuthInfoRBAC

type UserAuthInfoRBAC struct {
	UserId   string   `mapstructure:"key"`         // used by Api Key and JWT
	Username *string  `mapstructure:"user"`        // used by Basic Auth
	Password *string  `mapstructure:"password"`    // used by Basic Auth
	Groups   []string `mapstructure:"groups"`      // used by JWT Auth
	Roles    []string `mapstructure:"permissions"` // combination of roles from all user groups owned by user
}

func (*UserAuthInfoRBAC) GetControlType

func (u1 *UserAuthInfoRBAC) GetControlType() string

func (*UserAuthInfoRBAC) GetUserID

func (u1 *UserAuthInfoRBAC) GetUserID() string

type UserLoginInfo added in v0.0.24

type UserLoginInfo struct {
	Username     string        `json:"user_id"`
	AccessToken  *string       `json:"access_token"`
	RefreshToken *string       `json:"refresh_token"`
	ExpiresIn    time.Duration `json:"expires_in"`
	RefreshIn    time.Duration `json:"refresh_in"`
	Groups       []string      `json:"user_role"`
	Permissions  []string      `json:"user_permissions"`
}

Jump to

Keyboard shortcuts

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