feat: tipos auth (JWTClaims, Session, OAuthConfig, OAuthTokens, Permission, Role)
Fase 1 del issue 0010 — tipos base del sistema de auth en dominio infra. Define las estructuras que usaran jwt_*, session_*, oauth2_* y rbac_*. Añade dep golang.org/x/crypto/bcrypt para el hashing de passwords.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package infra
|
||||
|
||||
// JWTClaims contiene claims estandar y custom para un JWT.
|
||||
// Incluye los campos registrados mas comunes (sub, iss, aud, exp, iat)
|
||||
// y un mapa libre `Custom` para claims de aplicacion (ej: role, email).
|
||||
type JWTClaims struct {
|
||||
Subject string `json:"sub"`
|
||||
Issuer string `json:"iss,omitempty"`
|
||||
Audience string `json:"aud,omitempty"`
|
||||
ExpiresAt int64 `json:"exp"`
|
||||
IssuedAt int64 `json:"iat"`
|
||||
Custom map[string]any `json:"custom,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package infra
|
||||
|
||||
// OAuthConfig contiene la configuracion de un proveedor OAuth2.
|
||||
// Los Scopes se concatenan con espacio al construir la URL de autorizacion.
|
||||
type OAuthConfig struct {
|
||||
ClientID string `json:"client_id"`
|
||||
ClientSecret string `json:"client_secret"`
|
||||
AuthURL string `json:"auth_url"`
|
||||
TokenURL string `json:"token_url"`
|
||||
RedirectURL string `json:"redirect_url"`
|
||||
Scopes []string `json:"scopes"`
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package infra
|
||||
|
||||
// OAuthTokens contiene los tokens obtenidos de un flujo OAuth2.
|
||||
// ExpiresAt es Unix epoch seconds calculado a partir de expires_in del proveedor.
|
||||
type OAuthTokens struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
TokenType string `json:"token_type"`
|
||||
ExpiresAt int64 `json:"expires_at"`
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package infra
|
||||
|
||||
// Permission representa una accion sobre un recurso.
|
||||
// Ejemplo: {Resource: "users", Action: "delete"}.
|
||||
type Permission struct {
|
||||
Resource string `json:"resource"`
|
||||
Action string `json:"action"`
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package infra
|
||||
|
||||
// Role agrupa permisos bajo un nombre.
|
||||
// Ejemplo: {Name: "admin", Permissions: [{Resource:"users", Action:"delete"}, ...]}.
|
||||
type Role struct {
|
||||
Name string `json:"name"`
|
||||
Permissions []Permission `json:"permissions"`
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package infra
|
||||
|
||||
// Session representa una sesion de usuario almacenada en SQLite.
|
||||
// Token es un valor aleatorio opaco (32 bytes hex = 64 chars).
|
||||
// ExpiresAt y CreatedAt son Unix epoch seconds.
|
||||
type Session struct {
|
||||
Token string `json:"token"`
|
||||
UserID string `json:"user_id"`
|
||||
ExpiresAt int64 `json:"expires_at"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
Metadata map[string]any `json:"metadata,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user