Documentation
¶
Index ¶
- func AuthenticateMiddleware(next http.Handler, jwtSecret string) http.Handler
- func RegisterHandlers(r *mux.Router, service Service, logger log.Logger)
- func RoleMiddleware(next http.Handler, requiredRole string) http.Handler
- func WithUser(ctx context.Context, id primitive.ObjectID, name string) context.Context
- type Identity
- type LoginRequest
- type Service
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthenticateMiddleware ¶
func RegisterHandlers ¶
RegisterHandlers registers handlers for different HTTP requests.
func RoleMiddleware ¶
RoleMiddleware is a middleware to check the user's role
Types ¶
type Identity ¶
type Identity interface { // GetID returns the user ID. GetID() primitive.ObjectID // GetName returns the user name. GetName() string GetRole() []string }
Identity represents an authenticated user identity.
func CurrentUser ¶
CurrentUser returns the user identity from the given context. Nil is returned if no user identity is found in the context.
type LoginRequest ¶
func (LoginRequest) Validate ¶
func (m LoginRequest) Validate() error
Validate validates the CreateAlbumRequest fields.
type Service ¶
type Service interface { // authenticate authenticates a user using username and password. // It returns a JWT token if authentication succeeds. Otherwise, an error is returned. Login(ctx context.Context, username string, password string) (string, error) }
Service encapsulates the authentication logic.
func NewService ¶
func NewService(signingKey string, tokenExpiration int, logger log.Logger, userRepo user.Repository) Service
NewService creates a new authentication service.
Click to show internal directories.
Click to hide internal directories.