feat(auth): API-key authentication — corr_ bearer key acts as license owner
Closes the 'Public REST API' last mile: external callers authenticate with a per-license API key instead of a JWT. Additive and zero-regression: - JwtAuthGuard: a corr_-prefixed bearer token (or X-API-Key header) is validated via ApiKeysService.validateKey and sets request.user shaped like a JWT user, scoped to the key's license. JWTs are eyJ... and never collide with the corr_ prefix, so the existing JWT path is byte-for-byte unchanged. - API-key calls act AS the license owner: validateKey now resolves license.owner_user_id so sub is a real UUID — any @CurrentUser/created_by FK insert works and attributes correctly. (ApiKeysModule gains the License repo.) - PermissionsGuard: is_api_key principals get full access to their own license (always tenant-scoped). Future: scoped/read-only keys. Backend tsc green. Untested at runtime (no local DB) — needs a curl smoke test on Saturday's fresh stack before the roadmap item flips to shipped. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ApiKey } from '../../entities/api-key.entity';
|
||||
import { License } from '../../entities/license.entity';
|
||||
import { ApiKeysController } from './api-keys.controller';
|
||||
import { ApiKeysService } from './api-keys.service';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([ApiKey])],
|
||||
imports: [TypeOrmModule.forFeature([ApiKey, License])],
|
||||
controllers: [ApiKeysController],
|
||||
providers: [ApiKeysService],
|
||||
exports: [ApiKeysService],
|
||||
|
||||
Reference in New Issue
Block a user