-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support secrets
- Loading branch information
Tal Rofe
committed
Jun 3, 2022
1 parent
256cfa2
commit 4d5e6e4
Showing
54 changed files
with
578 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import { Routes } from '@nestjs/core'; | ||
|
||
import { AuthModule } from './modules/user/modules/auth/auth.module'; | ||
import { SecretsModule } from './modules/user/modules/secrets/secrets.module'; | ||
|
||
export const appRoutes: Routes = [ | ||
{ | ||
path: 'user', | ||
module: AuthModule, | ||
}, | ||
{ | ||
path: 'user', | ||
module: SecretsModule, | ||
}, | ||
]; |
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,5 @@ | ||
import { ValidationOptions, ValidateIf } from 'class-validator'; | ||
|
||
export function IsNullable(validationOptions?: ValidationOptions) { | ||
return ValidateIf((_object, value) => value !== null, validationOptions); | ||
} |
34 changes: 34 additions & 0 deletions
34
apps/backend/src/modules/database/client-secret.service.ts
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,34 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { PrismaService } from './prisma.service'; | ||
|
||
@Injectable() | ||
export class DBClientSecretService { | ||
constructor(private prisma: PrismaService) {} | ||
|
||
public async doesSecretBelongUser(userId: string, secretId: string) { | ||
const secretDB = await this.prisma.clientSecret.findFirst({ where: { userId, id: secretId } }); | ||
|
||
return secretDB !== null; | ||
} | ||
|
||
public async deleteSecret(secretId: string) { | ||
await this.prisma.clientSecret.delete({ where: { id: secretId } }); | ||
} | ||
|
||
public async revokeAllSecrets(userId: string) { | ||
await this.prisma.clientSecret.deleteMany({ where: { userId } }); | ||
} | ||
|
||
public async refreshSecret(secretId: string, newSecret: string) { | ||
await this.prisma.clientSecret.update({ where: { id: secretId }, data: { secret: newSecret } }); | ||
} | ||
|
||
public async editSecretLabel(secretId: string, newLabel: string) { | ||
await this.prisma.clientSecret.update({ where: { id: secretId }, data: { label: newLabel } }); | ||
} | ||
|
||
public async createSecret(userId: string, secret: string, label: string, expiration: Date | null) { | ||
await this.prisma.clientSecret.create({ data: { secret, userId, label, expiration } }); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { Global, Module } from '@nestjs/common'; | ||
import { DBClientSecretService } from './client-secret.service'; | ||
|
||
import { PrismaService } from './prisma.service'; | ||
import { DBUserService } from './user.service'; | ||
|
||
@Global() | ||
@Module({ | ||
providers: [PrismaService, DBUserService], | ||
exports: [DBUserService], | ||
providers: [PrismaService, DBUserService, DBClientSecretService], | ||
exports: [DBUserService, DBClientSecretService], | ||
}) | ||
export class DatabaseModule {} |
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,14 @@ | ||
const Routes = { | ||
CONTROLLER: 'auth', | ||
DELETE: 'delete', | ||
LOGIN: 'login', | ||
AUTO_LOGIN: 'auto-login', | ||
REGISTER: 'register', | ||
REFRESH_TOKEN: 'refresh-token', | ||
GITHUB_AUTH: 'github-auth', | ||
GITHUB_REDIRECT: 'github-redirect', | ||
GOOGLE_AUTH: 'google-auth', | ||
GOOGLE_REDIRECT: 'google-redirect', | ||
}; | ||
|
||
export default Routes; |
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
File renamed without changes.
Oops, something went wrong.