auth

package
v1.0.78 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package auth is a generated GoMock package.

Index

Constants

View Source
const UserKey contextKey = "user"

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(authService AuthService) mux.MiddlewareFunc

func GenerateJWT

func GenerateJWT(user *models.User, secret string, expiration time.Duration) (string, error)

func GenerateJWTConfig added in v1.0.55

func GenerateJWTConfig(user *models.User, cfg *models.AuthConfig, expiration time.Duration) (string, error)

GenerateJWTConfig generates a JWT using the configured algorithm.

func GenerateTokenPair

func GenerateTokenPair(user *models.User, config *models.AuthConfig) (*models.Token, error)

func GetUserFromContext

func GetUserFromContext(ctx context.Context) (*models.User, bool)

func HasPermission added in v1.0.55

func HasPermission(user *models.User, permission string, config *models.RBACConfig) bool

HasPermission checks if a user has a specific permission

func PermissionMiddleware added in v1.0.55

func PermissionMiddleware(permission string, config *models.RBACConfig) mux.MiddlewareFunc

PermissionMiddleware creates middleware that checks for specific permissions

func PublicJWKSJSON added in v1.0.55

func PublicJWKSJSON(cfg *models.AuthConfig) ([]byte, error)

PublicJWKSJSON builds a JWKS JSON document from the configured RSA keys. Currently derives the public key from JWTPrivateKeyPEM if RS256 is enabled.

func RBACMiddleware added in v1.0.55

func RBACMiddleware(requiredRole string) mux.MiddlewareFunc

func RouteProtectionMiddleware added in v1.0.55

func RouteProtectionMiddleware(config *models.RBACConfig) mux.MiddlewareFunc

RouteProtectionMiddleware creates middleware that enforces RBAC based on route configuration

Types

type Auth

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

func NewAuth

func NewAuth(config *models.AuthConfig, d db.Service) *Auth

func (*Auth) BeginOAuth

func (*Auth) BeginOAuth(_ context.Context, provider string) (string, error)

func (*Auth) CompleteOAuth

func (a *Auth) CompleteOAuth(ctx context.Context, provider string, gothUser *goth.User) (*models.Token, error)

func (*Auth) Config added in v1.0.55

func (a *Auth) Config() *models.AuthConfig

Config exposes a read-only pointer to the auth configuration for helpers like JWKS serving.

func (*Auth) LoginLocal

func (a *Auth) LoginLocal(ctx context.Context, username, password string) (*models.Token, error)

func (*Auth) RefreshToken

func (a *Auth) RefreshToken(ctx context.Context, refreshToken string) (*models.Token, error)

func (*Auth) VerifyToken

func (a *Auth) VerifyToken(_ context.Context, token string) (*models.User, error)

type AuthService

type AuthService interface {
	LoginLocal(ctx context.Context, username, password string) (*models.Token, error)
	BeginOAuth(ctx context.Context, provider string) (string, error)
	CompleteOAuth(ctx context.Context, provider string, user *goth.User) (*models.Token, error)
	RefreshToken(ctx context.Context, refreshToken string) (*models.Token, error)
	VerifyToken(ctx context.Context, token string) (*models.User, error)
}

type Claims

type Claims struct {
	UserID   string   `json:"user_id"`
	Email    string   `json:"email"`
	Provider string   `json:"provider"`
	Roles    []string `json:"roles"`
	KeyID    string   `json:"kid,omitempty"`
	jwt.RegisteredClaims
}

func ParseJWT

func ParseJWT(tokenString, secret string) (*Claims, error)

func ParseJWTConfig added in v1.0.55

func ParseJWTConfig(tokenString string, cfg *models.AuthConfig) (*Claims, error)

ParseJWTConfig verifies a JWT using the configured algorithm.

type JWK added in v1.0.55

type JWK struct {
	Kty string `json:"kty"`           // Key Type, e.g., "RSA"
	Kid string `json:"kid,omitempty"` // Key ID
	Use string `json:"use,omitempty"` // Public key use, e.g., "sig"
	Alg string `json:"alg,omitempty"` // Algorithm, e.g., "RS256"
	N   string `json:"n,omitempty"`   // Modulus, base64url
	E   string `json:"e,omitempty"`   // Exponent, base64url
}

JWK represents a single RSA public key in JWK format

type JWKSet added in v1.0.55

type JWKSet struct {
	Keys []JWK `json:"keys"`
}

JWKSet is a set of JWK keys

type MockAuthService

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

MockAuthService is a mock of AuthService interface.

func NewMockAuthService

func NewMockAuthService(ctrl *gomock.Controller) *MockAuthService

NewMockAuthService creates a new mock instance.

func (*MockAuthService) BeginOAuth

func (m *MockAuthService) BeginOAuth(ctx context.Context, provider string) (string, error)

BeginOAuth mocks base method.

func (*MockAuthService) CompleteOAuth

func (m *MockAuthService) CompleteOAuth(ctx context.Context, provider string, user *goth.User) (*models.Token, error)

CompleteOAuth mocks base method.

func (*MockAuthService) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockAuthService) LoginLocal

func (m *MockAuthService) LoginLocal(ctx context.Context, username, password string) (*models.Token, error)

LoginLocal mocks base method.

func (*MockAuthService) RefreshToken

func (m *MockAuthService) RefreshToken(ctx context.Context, refreshToken string) (*models.Token, error)

RefreshToken mocks base method.

func (*MockAuthService) VerifyToken

func (m *MockAuthService) VerifyToken(ctx context.Context, token string) (*models.User, error)

VerifyToken mocks base method.

type MockAuthServiceMockRecorder

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

MockAuthServiceMockRecorder is the mock recorder for MockAuthService.

func (*MockAuthServiceMockRecorder) BeginOAuth

func (mr *MockAuthServiceMockRecorder) BeginOAuth(ctx, provider any) *gomock.Call

BeginOAuth indicates an expected call of BeginOAuth.

func (*MockAuthServiceMockRecorder) CompleteOAuth

func (mr *MockAuthServiceMockRecorder) CompleteOAuth(ctx, provider, user any) *gomock.Call

CompleteOAuth indicates an expected call of CompleteOAuth.

func (*MockAuthServiceMockRecorder) LoginLocal

func (mr *MockAuthServiceMockRecorder) LoginLocal(ctx, username, password any) *gomock.Call

LoginLocal indicates an expected call of LoginLocal.

func (*MockAuthServiceMockRecorder) RefreshToken

func (mr *MockAuthServiceMockRecorder) RefreshToken(ctx, refreshToken any) *gomock.Call

RefreshToken indicates an expected call of RefreshToken.

func (*MockAuthServiceMockRecorder) VerifyToken

func (mr *MockAuthServiceMockRecorder) VerifyToken(ctx, token any) *gomock.Call

VerifyToken indicates an expected call of VerifyToken.

Jump to

Keyboard shortcuts

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