feat(auth): add GET /keys to list available key identifiers
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { AuthService } from './auth.service';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
@@ -8,6 +8,13 @@ import { LoginDto } from './dto/login.dto';
|
||||
export class AuthController {
|
||||
constructor(private readonly authService: AuthService) {}
|
||||
|
||||
@Get('keys')
|
||||
@ApiOperation({ summary: 'List available key identifiers from the keys directory' })
|
||||
@ApiResponse({ status: 200, description: 'List of key names', schema: { properties: { keys: { type: 'array', items: { type: 'string' } } } } })
|
||||
listKeys(): { keys: string[] } {
|
||||
return { keys: this.authService.listKeys() };
|
||||
}
|
||||
|
||||
@Post('login')
|
||||
@ApiOperation({ summary: 'Log in using a file key and return the session token' })
|
||||
@ApiResponse({ status: 201, description: 'Login successful', schema: { properties: { token: { type: 'string' }, sessionName: { type: 'string' } } } })
|
||||
|
||||
@@ -40,6 +40,13 @@ export class AuthService {
|
||||
);
|
||||
}
|
||||
|
||||
listKeys(): string[] {
|
||||
if (!fs.existsSync(this.keysDir)) return [];
|
||||
return fs.readdirSync(this.keysDir)
|
||||
.filter(f => f.endsWith('.json'))
|
||||
.map(f => path.basename(f, '.json'));
|
||||
}
|
||||
|
||||
async login(keyId: string, sessionName?: string): Promise<{ token: string; sessionName: string }> {
|
||||
const resolvedSession = sessionName ?? crypto.randomUUID();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user