@hgdc/auth 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +26 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -55,6 +55,32 @@ authComponent.registerRoutes(http, (ctx) => {
55
55
  })
56
56
  ```
57
57
 
58
+ ## Clés JWKS statiques côté Convex
59
+
60
+ Chaque appel HTTP à Convex avec un jeton (le rendu serveur de TanStack Start, `fetchAuthQuery`) fait vérifier ce jeton par le backend Convex, qui ne le met jamais en cache. Avec `getAuthConfigProvider()` seul, il va chercher les clés à `<site>/api/auth/convex/jwks` **à chaque appel** : sous charge, cette adresse répond 429 et la page tombe en erreur. Les clés se donnent donc en dur, par la variable `JWKS` du déploiement Convex :
61
+
62
+ ```ts
63
+ // convex/auth.config.ts
64
+ export default { providers: [getAuthConfigProvider({ jwks: process.env.JWKS })] } satisfies AuthConfig
65
+
66
+ // convex/auth.ts, dans les plugins
67
+ convex({ authConfig, jwks: process.env.JWKS })
68
+
69
+ // convex/authKeys.ts
70
+ export const latestJwks = internalAction({
71
+ args: {},
72
+ handler: async (ctx) => await createAuth(ctx).api.getLatestJwks(),
73
+ })
74
+ ```
75
+
76
+ Convex refuse un push dont `auth.config.ts` lit une variable absente : la mise en place se fait en deux temps, sur chaque déploiement (prod et dev).
77
+
78
+ 1. Déployer `authKeys.ts` et le plugin `convex({ authConfig, jwks: process.env.JWKS })`, `auth.config.ts` inchangé (le plugin accepte une variable absente).
79
+ 2. Poser la variable : `npx convex run authKeys:latestJwks --prod | npx convex env set JWKS --prod` (sans `--prod` pour le dev).
80
+ 3. Passer `jwks: process.env.JWKS` à `getAuthConfigProvider` et redéployer.
81
+
82
+ Un nouveau déploiement (préversion, local) pose `JWKS` avant son premier push. La variable contient la clé privée chiffrée : elle ne sort jamais du déploiement (ni affichée, ni copiée ailleurs). Après une rotation des clés, reposer la variable puis redéployer.
83
+
58
84
  ## Entrée commune `/auth/hgdc`
59
85
 
60
86
  Le menu « Produits » (`@hgdc/ui/account-menu`) envoie vers `https://<mot>.hgdc.ch/auth/hgdc`, pas vers la page d'accueil publique. Chaque produit monte cette route serveur, au même chemin :
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hgdc/auth",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Connexion HGDC : bouton « Se connecter avec HGDC », config better-auth et gardes Convex.",
5
5
  "license": "UNLICENSED",
6
6
  "homepage": "https://github.com/hugogebel-boop/hgdc-kit/tree/main/packages/auth#readme",