-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4061582
commit 7b1033b
Showing
21 changed files
with
506 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { | ||
Body, | ||
ClassSerializerInterceptor, | ||
Controller, | ||
Get, | ||
HttpCode, | ||
HttpStatus, Patch, | ||
Post, | ||
Query, | ||
Res, | ||
UseInterceptors | ||
} from '@nestjs/common'; | ||
import { ApiBadRequestResponse, ApiTags } from '@nestjs/swagger'; | ||
import { Response } from 'express'; | ||
import { InjectPinoLogger, PinoLogger } from 'nestjs-pino'; | ||
import { AnyRoles } from '../decorators/any-role.decorator'; | ||
import { CurrentUser } from '../decorators/current-user.decorator'; | ||
import { JwtAuth } from '../decorators/jwt-auth.decorator'; | ||
import { PublicRoute } from '../decorators/public-route.decorator'; | ||
import { UserContextDto } from '../user/user.dto'; | ||
import { ClaimConnectionDto, CreateOrUpdateSecretDto, Edition, RefreshConnectionDto } from './secrets.dto'; | ||
import { SecretsService } from './secrets.service'; | ||
|
||
@Controller('api/secrets') | ||
@JwtAuth() | ||
@ApiTags('Secrets') | ||
@UseInterceptors(ClassSerializerInterceptor) | ||
export class SecretsController { | ||
constructor( | ||
@InjectPinoLogger(SecretsController.name) private readonly logger: PinoLogger, | ||
private service: SecretsService) {} | ||
@Get('redirect') | ||
@HttpCode(HttpStatus.OK) | ||
@ApiBadRequestResponse({ description: 'Email already exists' }) | ||
async redirect(@Query('code') code: string, @Res() res: Response) { | ||
if (!code) { | ||
return res.send('The code is missing in url') | ||
} | ||
|
||
return res.type('html').type('text/html').send(`<script>if(window.opener){window.opener.postMessage({ 'code': '${encodeURIComponent(code)}' },'*')}</script> <html>Redirect succuesfully, this window should close now</html>`) | ||
} | ||
|
||
@Get('apps') | ||
@PublicRoute() | ||
@HttpCode(HttpStatus.OK) | ||
async apps(@CurrentUser() user?: UserContextDto, @Query('edition') edition?: Edition) { | ||
return this.service.getClientIds(edition, user?.roles.includes('admin')); | ||
} | ||
|
||
@Post('claim') | ||
@PublicRoute() | ||
@HttpCode(HttpStatus.OK) | ||
@ApiBadRequestResponse({ description: 'Email already exists' }) | ||
async claim(@Body() dto: ClaimConnectionDto) { | ||
return this.service.claim(dto); | ||
} | ||
|
||
@Post('refresh') | ||
@PublicRoute() | ||
@HttpCode(HttpStatus.OK) | ||
@ApiBadRequestResponse({ description: 'Email already exists' }) | ||
async refresh(@Body() appConnection: RefreshConnectionDto) { | ||
return this.service.refresh(appConnection); | ||
} | ||
|
||
@JwtAuth() | ||
@AnyRoles('admin') | ||
@Post() | ||
@HttpCode(HttpStatus.CREATED) | ||
@ApiBadRequestResponse({ description: 'Secret already exists' }) | ||
async create(@Body() dto: CreateOrUpdateSecretDto) { | ||
return this.service.create(dto); | ||
} | ||
|
||
@JwtAuth() | ||
@AnyRoles('admin') | ||
@Patch() | ||
@HttpCode(HttpStatus.OK) | ||
@ApiBadRequestResponse({ description: 'Secret already exists' }) | ||
async update(@Body() dto: CreateOrUpdateSecretDto) { | ||
return this.service.update(dto); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; | ||
import { IsOptional, IsString, IsUrl } from 'class-validator'; | ||
|
||
export enum Edition { | ||
COMMUNITY = 'ce', | ||
ENTERPRISE = 'ee', | ||
CLOUD = 'cloud', | ||
} | ||
|
||
export enum AuthorizationMethod { | ||
HEADER = 'HEADER', | ||
BODY = 'BODY', | ||
} | ||
|
||
export class RefreshConnectionDto { | ||
@ApiProperty() | ||
@IsString() | ||
refreshToken: string; | ||
|
||
@ApiProperty() | ||
@IsString() | ||
pieceName: string; | ||
|
||
@ApiProperty() | ||
@IsString() | ||
clientId: string; | ||
|
||
@ApiPropertyOptional() | ||
@IsOptional() | ||
edition?: Edition; | ||
|
||
@ApiPropertyOptional() | ||
@IsOptional() | ||
authorizationMethod?: AuthorizationMethod; | ||
|
||
@ApiProperty() | ||
@IsUrl() | ||
tokenUrl: string; | ||
} | ||
|
||
export class ClaimConnectionDto { | ||
@ApiProperty() | ||
@IsString() | ||
pieceName: string; | ||
|
||
@ApiProperty() | ||
@IsString() | ||
code: string; | ||
|
||
@ApiProperty() | ||
@IsString() | ||
clientId: string; | ||
|
||
@ApiProperty() | ||
@IsUrl() | ||
tokenUrl: string; | ||
|
||
@ApiPropertyOptional() | ||
@IsOptional() | ||
@IsString() | ||
codeVerifier?: string; | ||
|
||
@ApiPropertyOptional() | ||
@IsOptional() | ||
edition?: Edition; | ||
|
||
@ApiPropertyOptional() | ||
@IsOptional() | ||
authorizationMethod?: AuthorizationMethod; | ||
} | ||
|
||
export class CreateOrUpdateSecretDto { | ||
@ApiProperty() | ||
@IsString() | ||
pieceName: string; | ||
|
||
@ApiProperty() | ||
@IsString() | ||
clientSecret: string; | ||
|
||
@ApiProperty() | ||
@IsString() | ||
clientId: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { Module } from '@nestjs/common'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { TypeOrmExModule } from '@tookey/database'; | ||
import { SecretsRepository } from '@tookey/database'; | ||
import { SecretsController } from './secrets.controller'; | ||
import { SecretsService } from './secrets.service'; | ||
|
||
const SecretRepositories = TypeOrmExModule.forCustomRepository([SecretsRepository]); | ||
|
||
@Module({ | ||
imports: [ConfigModule, HttpModule, SecretRepositories], | ||
controllers: [SecretsController], | ||
providers: [SecretsService] | ||
}) | ||
export class SecretsModule {} |
Oops, something went wrong.