auth

package
v0.2.0-alpha.14 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingKID is returned when the token format is invalid and the kid field is missing in the token header.
	ErrMissingKID = errors.Unauthorized(reasonUnauthorized, "Invalid token format: missing kid field in header")
	// ErrSecretDisabled is returned when the SecretID is disabled.
	ErrSecretDisabled = errors.Unauthorized(reasonUnauthorized, "SecretID is disabled")
)
View Source
var AuthnProviderSet = wire.NewSet(NewAuthn, wire.Bind(new(AuthnInterface), new(*authnImpl)))

AuthnProviderSet is authn providers.

View Source
var AuthzProviderSet = wire.NewSet(NewAuthz, wire.Bind(new(AuthzInterface), new(*authzImpl)), LoggerProviderSet)

AuthzProviderSet defines a wire set for authorization.

View Source
var LoggerProviderSet = wire.NewSet(NewLogger, wire.Bind(new(clog.Logger), new(*kafkaLogger)))

LoggerProviderSet defines a wire set for creating a kafkaLogger instance to implement log.Logger interface.

ProviderSet is a Wire provider set that creates a new instance of auth.

Functions

func NewAuth

func NewAuth(authn AuthnInterface, authz AuthzInterface) *auth

NewAuth is a constructor function that creates a new instance of auth struct.

func NewAuthn

func NewAuthn(setter TemporarySecretSetter) (*authnImpl, error)

NewAuthn returns a new instance of authn.

func NewAuthz

func NewAuthz(db *gorm.DB, redisOpts *genericoptions.RedisOptions, logger clog.Logger) (*authzImpl, error)

NewAuthz creates a new authorization instance using the provided database, Redis options, and logger.

func NewLogger

func NewLogger(kafkaOpts *genericoptions.KafkaOptions) (*kafkaLogger, error)

NewLogger creates a new kafkaLogger instance.

Types

type AuditMessage

type AuditMessage struct {
	Matcher   string     `protobuf:"bytes,1,opt,name=matcher,proto3" json:"matcher,omitempty"`
	Request   []any      `protobuf:"bytes,2,opt,name=request,proto3" json:"request,omitempty"`
	Result    bool       `protobuf:"bytes,3,opt,name=result,proto3" json:"result,omitempty"`
	Explains  [][]string `protobuf:"bytes,4,opt,name=explains,proto3" json:"explains,omitempty"`
	Timestamp int64      `protobuf:"bytes,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
}

AuditMessage is the message structure for log messages.

type AuthProvider

type AuthProvider interface {
	AuthnInterface
	AuthzInterface
}

AuthProvider is an interface that combines both the AuthnInterface and AuthzInterface interfaces.

type AuthnInterface

type AuthnInterface interface {
	// Sign is used to generate a access token. userID is the jwt identity key.
	Sign(ctx context.Context, userID string) (authn.IToken, error)
	// Verify is used to verify a access token. If the verification
	// is successful, userID will be returned.
	Verify(accessToken string) (string, error)
}

AuthnInterface defines the interface for authentication.

type AuthzInterface

type AuthzInterface interface {
	Authorize(rvals ...any) (bool, error)
}

AuthzInterface defines the interface for authorization.

type TemporarySecretSetter

type TemporarySecretSetter interface {
	Get(ctx context.Context, secretID string) (*model.SecretM, error)
	Set(ctx context.Context, userID string, expires int64) (*model.SecretM, error)
}

SecretSetter is used to set or get a temporary secret key pairs.

Jump to

Keyboard shortcuts

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