@amsom-habitat/nest-auth
v2.0.0
Published
Garde de la plateforme API Métier V2 : clé de gateway, lecture du JWT Ed25519 (@Pec, @CurrentUser), signature/vérification Ed25519.
Readme
@amsom-habitat/nest-auth
Garde d'une api derrière la gateway de la plateforme.
GatewayKeyGuard(global) : exigeX-Gateway-Keyparmi les clés acceptées (empreintes comparées à temps constant) ;@SkipGatewayKey()l'exempte (sondes).JwtAuthGuard(global) : la gateway a déjà vérifié le JWT ; ici il est décodé pour@Pec(),exigerPec(),@PecObligatoire(),@CurrentUser(). Token absent → 401 sauf@Public().Ed25519JwtService: signe/vérifie les JWT EdDSA au format sodium d'ApiAuth (private.key= graine 32 o ‖ clé publique 32 o). Clés lues à la demande, ou au démarrage aveccanSign/verifySignature.
AuthModule.forRoot({ gatewayKeys: ['…'], keysDir: '/app/config/jwt' })
AuthModule.forRootAsync({ inject: [ConfigService], useFactory: (c) => ({ gatewayKeys: … }) })| Option | Défaut |
|---|---|
| gatewayKeys | GATEWAY_API_KEYS (virgules) |
| requireGatewayKey | true : liste vide → erreur au démarrage |
| keysDir | JWT_KEYS_DIR, sinon config/jwt (résolu en absolu) |
| canSign | false ; true sur api-connexion : private.key exigée au démarrage |
| verifySignature | false ; true : l'api vérifie la signature (pas l'expiration, gérée par la gateway) |
En général importé via SocleModule.forRoot({ auth }) de @amsom-habitat/nest-socle.
Migration 1.x → 2.0
| 1.x | 2.0 |
|---|---|
| JwtAuthModule | AuthModule |
| OptionsAuth / clesGateway / dossierCles | AuthOptions / gatewayKeys / keysDir |
| @HorsGateway() | @SkipGatewayKey() |
| ENTETE_CLE_GATEWAY | GATEWAY_KEY_HEADER |
| JwtService (@nestjs/jwt) injecté | Ed25519JwtService |
| @CurrentUser() user: JwtUser | @CurrentUser() user: JwtUser \| null |
| OPTIONS_AUTH, resoudreOptionsAuth, IS_PUBLIC_KEY, HORS_GATEWAY_KEY | internes, plus exportés |
| Pec, PecObligatoire, exigerPec, PecAgent | inchangés |
