Skip to content

auth

@mmm/auth

Monorepo für die Auth-Domain mit klar getrennten Bereichen für Verträge, Angular-UI, NestJS-Server und Prisma.

Struktur

  • contracts Frameworkfreie Auth-Verträge und gemeinsame Transporttypen.
  • frontend Angular-basierte UI-Bausteine für Auth, Routing und Authorization.
  • backend NestJS-basierte Server-Bausteine für Core-, Password-, OAuth- und OIDC-Authentifizierung.
  • prisma Prisma-spezifische Artefakte der Auth-Domain.
  • legacy Historische Referenz. Neue Struktur und neue Imports dürfen davon nicht abhängen.

Architekturregeln

  • contracts bleibt frameworkfrei.
  • frontend darf contracts verwenden, aber kein NestJS- oder Prisma-spezifisches Verhalten enthalten.
  • backend darf contracts verwenden, aber kein Angular-spezifisches Verhalten enthalten.
  • permissions darf backend verwenden, aber kein Angular-spezifisches Verhalten enthalten.
  • prisma ist optionaler Infrastrukturteil und bleibt von UI und Server entkoppelt.
  • Auth und Authorization bleiben getrennt geschnitten.
  • Provider-spezifische Themen liegen unter password, oauth und oidc, nicht verstreut über Legacy-Pfade.

Öffentliche Entry Points

  • @mmm/auth/contracts
  • @mmm/auth/contracts/core
  • @mmm/auth/contracts/password
  • @mmm/auth/contracts/oauth
  • @mmm/auth/ui
  • @mmm/auth/server
  • @mmm/auth/server/core
  • @mmm/auth/server/password
  • @mmm/auth/server/oauth
  • @mmm/auth/server/oidc
  • @mmm/auth/server/permissions
  • @mmm/auth/prisma

Kompatibilitäts-Exports für ./frontend und ./backend bleiben vorerst erhalten, sollten aber mittelfristig durch ./ui und ./server ersetzt werden.

Build

Terminal window
pnpm run build

Das baut in Reihenfolge:

  1. contracts
  2. frontend
  3. backend
  4. permissions

Beispiel UI

import { AuthUiModule } from "@mmm/auth/ui";
AuthUiModule.forRoot({
core: {
apiBaseUrl: "/api",
tokenStorage: "sessionStorage",
},
password: {
loginEndpoint: "/auth/login",
postLoginRedirectUrl: "/",
},
oauth: {
enabledProviders: ["microsoft"],
postLoginRedirectUrl: "/",
},
});

Beispiel Server

import { AuthServerModule } from "@mmm/auth/server";
AuthServerModule.forRootAsync({
jwt: { secret: jwtSecret },
core: {
inject: [PRISMA_CLIENT],
useFactory: (prisma: PrismaClient) => ({
resolver: new PrismaAuthResolver(prisma),
options: {
rolling: {
enabled: true,
accessTokenTtlSeconds: sessionLength,
renewWhenSecondsLeft: sessionLength,
},
},
}),
},
password: {
inject: [PRISMA_CLIENT],
useFactory: (prisma: PrismaClient) => ({
validator: new PrismaPasswordValidator(prisma),
options: {
accessTokenTtlSeconds: sessionLength,
renewWhenSecondsLeft: sessionLength,
},
}),
},
oauth: {
inject: [PRISMA_CLIENT],
useFactory: (prisma: PrismaClient) => ({
resolver: new PrismaAuthOAuthResolver(prisma),
options: {
backendBaseUrl: process.env.BACKEND_BASE_URL!,
frontendBaseUrl: process.env.FRONTEND_BASE_URL!,
frontendCallbackPath: "/login/callback",
providers: {
microsoft: {
flowType: "oauth2_oidc",
clientId: process.env.MICROSOFT_OAUTH_CLIENT_ID!,
clientSecret: process.env.MICROSOFT_OAUTH_CLIENT_SECRET!,
},
},
},
}),
},
});

Weiterführende Doku