mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-16 16:14:43 -04:00

This ensures stack traces are helpful at the cost of a slightly lower performance (one more tick in the event loop). Fixes #838 Signed-off-by: David Mehren <git@herrmehren.de>
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
HttpCode,
|
|
Param,
|
|
Post,
|
|
} from '@nestjs/common';
|
|
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
|
import { AuthService } from '../../../auth/auth.service';
|
|
import { TimestampMillis } from '../../../utils/timestamp';
|
|
import { AuthTokenDto } from '../../../auth/auth-token.dto';
|
|
import { AuthTokenWithSecretDto } from '../../../auth/auth-token-with-secret.dto';
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
|
|
@ApiTags('tokens')
|
|
@Controller('tokens')
|
|
export class TokensController {
|
|
constructor(
|
|
private readonly logger: ConsoleLoggerService,
|
|
private authService: AuthService,
|
|
) {
|
|
this.logger.setContext(TokensController.name);
|
|
}
|
|
|
|
@Get()
|
|
async getUserTokens(): Promise<AuthTokenDto[]> {
|
|
// ToDo: Get real userName
|
|
return (
|
|
await this.authService.getTokensByUsername('hardcoded')
|
|
).map((token) => this.authService.toAuthTokenDto(token));
|
|
}
|
|
|
|
@Post()
|
|
async postTokenRequest(
|
|
@Body('label') label: string,
|
|
@Body('validUntil') validUntil: TimestampMillis,
|
|
): Promise<AuthTokenWithSecretDto> {
|
|
// ToDo: Get real userName
|
|
return await this.authService.createTokenForUser(
|
|
'hardcoded',
|
|
label,
|
|
validUntil,
|
|
);
|
|
}
|
|
|
|
@Delete('/:keyId')
|
|
@HttpCode(204)
|
|
async deleteToken(@Param('keyId') keyId: string) {
|
|
return await this.authService.removeToken(keyId);
|
|
}
|
|
}
|