+ La connexion a échoué
+ Réessayez dans quelques instants, ou revenez plus tard.
+ ← Retour aux formations
+
+
diff --git a/src/pages/connexion.ts b/src/pages/connexion.ts
new file mode 100644
index 0000000..19cb0ab
--- /dev/null
+++ b/src/pages/connexion.ts
@@ -0,0 +1,22 @@
+import type { APIRoute } from 'astro';
+import { randomBytes } from 'node:crypto';
+import { authUrl, pkcePair } from '../lib/oidc';
+
+const sanitizeNext = (raw: string | null): string =>
+ raw && raw.startsWith('/') && !raw.startsWith('//') ? raw : '/';
+
+export const GET: APIRoute = async ({ url, cookies, redirect }) => {
+ const state = randomBytes(16).toString('base64url');
+ const { verifier, challenge } = pkcePair();
+ const next = sanitizeNext(url.searchParams.get('next'));
+ const opts = { httpOnly: true, secure: true, sameSite: 'lax' as const, path: '/', maxAge: 600 };
+ cookies.set('oidc_state', state, opts);
+ cookies.set('oidc_verifier', verifier, opts);
+ cookies.set('oidc_next', next, opts);
+ try {
+ return redirect(await authUrl(state, challenge), 302);
+ } catch (err) {
+ console.error('[oidc] connexion failed:', (err as Error).message);
+ return redirect('/connexion-erreur', 302);
+ }
+};
diff --git a/src/pages/cours/[slug]/[module]/[chapitre].astro b/src/pages/cours/[slug]/[module]/[chapitre].astro
index e774ce8..9b20b63 100644
--- a/src/pages/cours/[slug]/[module]/[chapitre].astro
+++ b/src/pages/cours/[slug]/[module]/[chapitre].astro
@@ -4,7 +4,9 @@ import Nav from '../../../../components/Nav.astro';
import { bySlug } from '../../../../config/courses';
import { getCourseBooks, getChapterHtml } from '../../../../lib/moodle';
import { sanitizeHtml } from '../../../../lib/sanitize';
+import { verifySession, SESSION_COOKIE } from '../../../../lib/session';
+const user = verifySession(Astro.cookies.get(SESSION_COOKIE)?.value);
const course = bySlug(Astro.params.slug ?? '');
const mMatch = /^module-(\d+)$/.exec(Astro.params.module ?? '');
const cMatch = /^chapitre-(\d+)$/.exec(Astro.params.chapitre ?? '');
@@ -30,7 +32,7 @@ const next = ci < mod.chapters.length - 1 ? `/cours/${course.slug}/module-${mi +
: mi < modules.length - 1 ? `/cours/${course.slug}/module-${mi + 2}/chapitre-1` : null;
---