auth

package
v1.0.58-beta Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("INVALID CREDENTIALS")
	ErrInvalidToken       = errors.New("INVALID TOKEN")
	ErrTokenExpired       = errors.New("TOKEN EXPIRED")
	ErrInvalidScope       = errors.New("INVALID SCOPE")
)

Functions

func HashPassword

func HashPassword(password string) ([]byte, error)

func VerifyPassword

func VerifyPassword(password string, hashedPassword []byte) bool

Types

type AuthRequest

type AuthRequest struct {
	Username string   `json:"username,omitempty"`
	Password string   `json:"password,omitempty"`
	Scope    string   `json:"scope,omitempty"`
	Service  string   `json:"service,omitempty"`
	Type     AuthType `json:"type,omitempty"`
}

type AuthService

type AuthService interface {
	Authenticate(ctx context.Context, req AuthRequest) (interface{}, error)
	ValidateToken(ctx context.Context, token string) (*Claims, error)
	RefreshToken(ctx context.Context, refreshToken string) (*WebAuthResponse, error)
	RevokeToken(ctx context.Context, token string) error
	GetPermissions(ctx context.Context, subject string) ([]models.Permission, error)
	HasPermission(ctx context.Context, subject string, perm models.Permission) bool
}

func NewAuthService

func NewAuthService(
	repo repository.Repository,
	permManager *permissions.PermissionManager,
	signKey *rsa.PrivateKey,
	verifyKey *rsa.PublicKey,
	cfg *models.Config,
) AuthService

type AuthType

type AuthType string
const (
	AuthTypeWeb      AuthType = "web"
	AuthTypeRegistry AuthType = "registry"
)

type Claims

type Claims struct {
	// STANDARD CLAIM
	Subject      string           `json:"sub"`
	Audience     string           `json:"aud"`
	ExpiresAt    *jwt.NumericDate `json:"exp"`
	IssuedAt     *jwt.NumericDate `json:"iat"`
	NotBefore    *jwt.NumericDate `json:"nbf,omitempty"`
	Issuer       string           `json:"iss"`
	JwtID        string           `json:"jti,omitempty"`
	AllowReissue bool             `json:"allow_reissue,omitempty"`

	// REGISTRY CLAIM
	Access []models.ResourceActions `json:"access"`
}

func (Claims) Valid

func (c Claims) Valid() error

type Middleware

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

func NewMiddleware

func NewMiddleware(auth AuthService, cfg *models.Config, log *logging.LogService) *Middleware

func (*Middleware) AuthMiddleware

func (m *Middleware) AuthMiddleware(next http.Handler) http.Handler

WEB UI AUTH

func (*Middleware) RegistryAuthMiddleware

func (m *Middleware) RegistryAuthMiddleware(next http.Handler) http.Handler

REGISTRY AUTH MIDDLEWARE

type RegAuthResponse

type RegAuthResponse struct {
	AccessToken string    `json:"access_token"`
	ExpiresIn   int       `json:"expires_in"`
	IssuedAt    time.Time `json:"issued_at"`
	TokenType   string    `json:"token_type"`
}

type TokenManager

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

func NewTokenManager

func NewTokenManager(signKey *rsa.PrivateKey, verifyKey *rsa.PublicKey) *TokenManager

func (*TokenManager) GenerateToken

func (tm *TokenManager) GenerateToken(claims *Claims) (string, error)

func (*TokenManager) RevokeToken

func (tm *TokenManager) RevokeToken(token string) error

func (*TokenManager) ValidateToken

func (tm *TokenManager) ValidateToken(tokenString string) (*Claims, error)

type WebAuthResponse

type WebAuthResponse struct {
	Token     string    `json:"token,omitempty"`
	ExpiresIn int       `json:"expires_in,omitempty"`
	IssuedAt  time.Time `json:"issued_at,omitempty"`
	Username  string    `json:"username,omitempty"`
	Groups    []string  `json:"groups,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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