Documentation
¶
Overview ¶
Package auth is a generated GoMock package.
Index ¶
- Constants
- func AuthMiddleware(authService AuthService) mux.MiddlewareFunc
- func GenerateJWT(user *models.User, secret string, expiration time.Duration) (string, error)
- func GenerateJWTConfig(user *models.User, cfg *models.AuthConfig, expiration time.Duration) (string, error)
- func GenerateTokenPair(user *models.User, config *models.AuthConfig) (*models.Token, error)
- func GetUserFromContext(ctx context.Context) (*models.User, bool)
- func HasPermission(user *models.User, permission string, config *models.RBACConfig) bool
- func PermissionMiddleware(permission string, config *models.RBACConfig) mux.MiddlewareFunc
- func PublicJWKSJSON(cfg *models.AuthConfig) ([]byte, error)
- func RBACMiddleware(requiredRole string) mux.MiddlewareFunc
- func RouteProtectionMiddleware(config *models.RBACConfig) mux.MiddlewareFunc
- type Auth
- func (*Auth) BeginOAuth(_ context.Context, provider string) (string, error)
- func (a *Auth) CompleteOAuth(ctx context.Context, provider string, gothUser *goth.User) (*models.Token, error)
- func (a *Auth) Config() *models.AuthConfig
- func (a *Auth) LoginLocal(ctx context.Context, username, password string) (*models.Token, error)
- func (a *Auth) RefreshToken(ctx context.Context, refreshToken string) (*models.Token, error)
- func (a *Auth) VerifyToken(_ context.Context, token string) (*models.User, error)
- type AuthService
- type Claims
- type JWK
- type JWKSet
- type MockAuthService
- func (m *MockAuthService) BeginOAuth(ctx context.Context, provider string) (string, error)
- func (m *MockAuthService) CompleteOAuth(ctx context.Context, provider string, user *goth.User) (*models.Token, error)
- func (m *MockAuthService) EXPECT() *MockAuthServiceMockRecorder
- func (m *MockAuthService) LoginLocal(ctx context.Context, username, password string) (*models.Token, error)
- func (m *MockAuthService) RefreshToken(ctx context.Context, refreshToken string) (*models.Token, error)
- func (m *MockAuthService) VerifyToken(ctx context.Context, token string) (*models.User, error)
- type MockAuthServiceMockRecorder
- func (mr *MockAuthServiceMockRecorder) BeginOAuth(ctx, provider any) *gomock.Call
- func (mr *MockAuthServiceMockRecorder) CompleteOAuth(ctx, provider, user any) *gomock.Call
- func (mr *MockAuthServiceMockRecorder) LoginLocal(ctx, username, password any) *gomock.Call
- func (mr *MockAuthServiceMockRecorder) RefreshToken(ctx, refreshToken any) *gomock.Call
- func (mr *MockAuthServiceMockRecorder) VerifyToken(ctx, token any) *gomock.Call
Constants ¶
const UserKey contextKey = "user"
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware(authService AuthService) mux.MiddlewareFunc
func GenerateJWT ¶
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 HasPermission ¶ added in v1.0.55
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 (*Auth) BeginOAuth ¶
func (*Auth) CompleteOAuth ¶
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 (*Auth) RefreshToken ¶
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 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 ¶
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 ¶
func (m *MockAuthService) EXPECT() *MockAuthServiceMockRecorder
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 ¶
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.