renommage lassistanoque
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
"trankilou.fr/lassistanoque/backend/internal/domain"
|
||||
)
|
||||
|
||||
type Credentials struct {
|
||||
Method string // "password" ou "oidc"
|
||||
Email string
|
||||
Password string
|
||||
OIDCCode string
|
||||
}
|
||||
|
||||
type Registration struct {
|
||||
Method string `json:"method"` // "password" ou "oidc"
|
||||
Email string `json:"email"`
|
||||
Firstname string `json:"firstname"`
|
||||
Lastname string `json:"lastname"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
User *domain.User
|
||||
AccessToken string
|
||||
RefreshToken string
|
||||
ExpiresAt time.Time
|
||||
}
|
||||
|
||||
const ContextUserIDKey = "userID"
|
||||
const ContextEmailKey = "userEmail"
|
||||
const ContextNameKey = "userName"
|
||||
const ContextAdminKey = "admin"
|
||||
|
||||
// Interface définie ici car c'est un port propre au cas d'usage "auth"
|
||||
type Authenticator interface {
|
||||
Authenticate(ctx context.Context, creds Credentials) (*Session, error)
|
||||
Register(ctx context.Context, registration Registration) (*Session, error)
|
||||
}
|
||||
|
||||
type TokenManager interface {
|
||||
GenerateAccessToken(user *domain.User) (string, time.Time, error)
|
||||
GenerateRefreshToken(userID string) (string, time.Time, error)
|
||||
ParseAndValidate(tokenString string) (*domain.User, error)
|
||||
TokenMiddleware(next echo.HandlerFunc) echo.HandlerFunc
|
||||
}
|
||||
Reference in New Issue
Block a user