Documentation ¶
Overview ¶
Package auth provides JWT token management functionality
Index ¶
- type ACLManager
- type AuthCodeRequest
- type AuthFlowRequest
- type AuthFlowResponse
- type AuthTokenResponse
- type GoogleProvider
- type JWTClaims
- type JWTManager
- type KeyManager
- type MockOAuthProvider
- type OAuthManager
- type OAuthProvider
- type UserManager
- func (um *UserManager) ActivateUser(ctx context.Context, uuid uuid.UUID) error
- func (um *UserManager) CreateUser(ctx context.Context, name, email string, status types.UserStatus) (*types.User, error)
- func (um *UserManager) DeactivateUser(ctx context.Context, uuid uuid.UUID) error
- func (um *UserManager) GetAnonymousUser(ctx context.Context) (*types.User, error)
- func (um *UserManager) GetPaginatedUsers(ctx context.Context, filter types.UserFilter, option types.UserFilterOption) (types.PaginatedUsers, error)
- func (um *UserManager) GetUser(ctx context.Context, uuid uuid.UUID) (*types.User, error)
- func (um *UserManager) GetUserByEmail(ctx context.Context, email string) (*types.User, error)
- func (um *UserManager) RegisterRoutes(r chi.Router)
- func (um *UserManager) ResolveUserFromRequest(next http.Handler) http.Handler
- func (um *UserManager) UpdateUserRoles(ctx context.Context, uuid uuid.UUID, roles []types.UserRole) error
- func (um *UserManager) UpdateUserStatus(ctx context.Context, uuid uuid.UUID, status types.UserStatus) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ACLManager ¶
type ACLManager struct {
// contains filtered or unexported fields
}
func NewACLManager ¶
func NewACLManager(logger *logrus.Logger, enableAuth bool) ACLManager
func (*ACLManager) GetAuthenticatedUserFromContext ¶
GetAuthenticatedUserFromContext retrieves the user from the context.
type AuthCodeRequest ¶
type AuthCodeRequest struct { AuthFlow struct { Provider string `json:"provider"` AuthCode string `json:"auth_code"` State string `json:"state"` } `json:"auth_flow"` }
AuthCodeRequest represents the request body for handling an OAuth code
type AuthFlowRequest ¶
type AuthFlowRequest struct { AuthFlow struct { Provider string `json:"provider"` CurrentURL string `json:"current_url,omitempty"` } `json:"auth_flow"` }
AuthFlowRequest represents the request body for initiating an OAuth flow
type AuthFlowResponse ¶
type AuthFlowResponse struct { AuthFlow struct { Provider string `json:"provider"` AuthRedirectURL string `json:"auth_redirect_url"` State string `json:"state"` } `json:"auth_flow"` }
AuthFlowResponse represents the response body for initiating an OAuth flow
type AuthTokenResponse ¶
type AuthTokenResponse struct {
AccessToken string `json:"access_token"`
}
AuthTokenResponse represents the response body for handling an OAuth code
type GoogleProvider ¶
type GoogleProvider struct {
// contains filtered or unexported fields
}
func NewGoogleProvider ¶
func NewGoogleProvider(clientID, clientSecret, redirectURL string) *GoogleProvider
func (*GoogleProvider) ExchangeCodeForToken ¶
func (*GoogleProvider) GetAuthURL ¶
func (gp *GoogleProvider) GetAuthURL(state string) string
func (*GoogleProvider) GetUserInfo ¶
func (gp *GoogleProvider) GetUserInfo(ctx context.Context, accessToken string) (*types.OAuthUserInfo, error)
type JWTClaims ¶
type JWTClaims struct {
jwt.RegisteredClaims
}
JWTClaims represents the structure of your custom claims
type JWTManager ¶
type JWTManager struct {
// contains filtered or unexported fields
}
JWTManager handles JWT operations
func NewJWTManager ¶
func NewJWTManager(keyManager *KeyManager, userManager *UserManager, logger *logrus.Logger, skipAuthEndpoints []string) *JWTManager
NewJWTManager creates a new JWTManager with the given KeyManager, UserManager and logger
func (*JWTManager) AuthMiddleware ¶
AuthMiddleware is a middleware function that accepts multiple arguments
func (*JWTManager) IssueToken ¶
func (m *JWTManager) IssueToken(ctx context.Context, userUUID uuid.UUID, audience []string, expiration time.Duration) (string, error)
IssueToken creates and signs a new JWT token for a user
func (*JWTManager) ValidateToken ¶
func (m *JWTManager) ValidateToken(tokenString string) (*JWTClaims, error)
ValidateToken verifies the given token and returns the claims if valid
type KeyManager ¶
type KeyManager struct {
// contains filtered or unexported fields
}
KeyManager handles RSA key pair operations
func NewKeyManager ¶
func NewKeyManager(storage storage.Storage, logger *logrus.Logger) *KeyManager
NewKeyManager creates a new KeyManager instance
func (*KeyManager) GetKeyPair ¶
func (km *KeyManager) GetKeyPair() (*rsa.PrivateKey, *rsa.PublicKey, error)
GetKeyPair retrieves the key pair from storage or generates a new one if not found
type MockOAuthProvider ¶
type MockOAuthProvider struct { BaseURL string ClientID string ClientSecret string RedirectURL string }
MockOAuthProvider is a mock OAuth provider for testing purposes
func NewMockOAuthProvider ¶
func NewMockOAuthProvider(baseURL, clientID, clientSecret, redirectURL string) *MockOAuthProvider
NewMockOAuthProvider creates a new MockOAuthProvider
func (*MockOAuthProvider) ExchangeCodeForToken ¶
ExchangeCodeForToken exchanges an authorization code for an access token
func (*MockOAuthProvider) GetAuthURL ¶
func (m *MockOAuthProvider) GetAuthURL(state string) string
GetAuthURL returns the URL to redirect the user to for authorization
func (*MockOAuthProvider) GetUserInfo ¶
func (m *MockOAuthProvider) GetUserInfo(ctx context.Context, token string) (*types.OAuthUserInfo, error)
GetUserInfo retrieves user information using an access token
type OAuthManager ¶
type OAuthManager struct {
// contains filtered or unexported fields
}
OAuthManager handles OAuth operations
func NewOAuthManager ¶
func NewOAuthManager(providers map[string]OAuthProvider, userManager *UserManager, jwtManager *JWTManager, logger *logrus.Logger) *OAuthManager
NewOAuthManager creates a new OAuthManager with the given providers, UserManager, JWTManager, and logger
func (*OAuthManager) HandleAuthCode ¶
func (om *OAuthManager) HandleAuthCode(w http.ResponseWriter, r *http.Request)
HandleAuthCode handles an OAuth code and returns an access token
func (*OAuthManager) InitiateAuthFlow ¶
func (om *OAuthManager) InitiateAuthFlow(w http.ResponseWriter, r *http.Request)
InitiateAuthFlow initiates an OAuth flow with the given provider
func (*OAuthManager) RegisterRoutes ¶
func (om *OAuthManager) RegisterRoutes(r chi.Router)
RegisterRoutes registers the OAuth routes
type OAuthProvider ¶
type OAuthProvider interface { GetAuthURL(state string) string ExchangeCodeForToken(ctx context.Context, code string) (string, error) GetUserInfo(ctx context.Context, token string) (*types.OAuthUserInfo, error) }
OAuthProvider is an interface for OAuth providers
type UserManager ¶
type UserManager struct {
// contains filtered or unexported fields
}
UserManager is a manager for user operations.
func NewUserManager ¶
func NewUserManager(storage storage.Storage, logger *logrus.Logger, aclManager ACLManager, superAdminEmail string) *UserManager
NewUserManager creates a new instance of UserManager with the given storage and logger.
func (*UserManager) ActivateUser ¶
ActivateUser sets the user status to active.
func (*UserManager) CreateUser ¶
func (um *UserManager) CreateUser(ctx context.Context, name, email string, status types.UserStatus) (*types.User, error)
CreateUser creates a new user with the given name, email, and status.
func (*UserManager) DeactivateUser ¶
DeactivateUser sets the user status to inactive.
func (*UserManager) GetAnonymousUser ¶
GetAnonymousUser fetches the anonymous user data
func (*UserManager) GetPaginatedUsers ¶
func (um *UserManager) GetPaginatedUsers(ctx context.Context, filter types.UserFilter, option types.UserFilterOption) (types.PaginatedUsers, error)
func (*UserManager) GetUserByEmail ¶
GetUserByEmail fetches the user details from the storage.
func (*UserManager) RegisterRoutes ¶
func (um *UserManager) RegisterRoutes(r chi.Router)
func (*UserManager) ResolveUserFromRequest ¶
func (um *UserManager) ResolveUserFromRequest(next http.Handler) http.Handler
ResolveUserFromRequest is a middleware that extracts the user UUID from the request and fetches the user details from the storage.
func (*UserManager) UpdateUserRoles ¶
func (um *UserManager) UpdateUserRoles(ctx context.Context, uuid uuid.UUID, roles []types.UserRole) error
UpdateUserRoles updates the roles of the user with the given UUID.
func (*UserManager) UpdateUserStatus ¶
func (um *UserManager) UpdateUserStatus(ctx context.Context, uuid uuid.UUID, status types.UserStatus) error
UpdateUserStatus updates the status of the user with the given UUID.