Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: one time password #453

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ModelsModule } from '@tractr/generated-nestjs-models';
import { USER_SERVICE } from '@tractr/generated-nestjs-models-common';
import {
AuthenticationModule,
JwtGlobalAuthGuard,
JwtTwoFactorGuard,
} from '@tractr/nestjs-authentication';
import {
CaslExceptionInterceptor,
Expand Down Expand Up @@ -44,10 +44,16 @@ import { MailerModule } from '@tractr/nestjs-mailer';
useFactory: (defaultOptions) => ({
...defaultOptions,
userConfig: {
...defaultOptions.userConfig,
customSelect: getSelectPrismaUserQuery(),
idField: 'id',
loginField: 'email',
passwordField: 'password',
emailField: 'email',
customSelect: getSelectPrismaUserQuery({ otp: true }),
otpField: 'otp',
formatUser: ({ ...user }) => user,
},
userService: USER_SERVICE,
otp: true,
}),
}),
FileStorageModule.registerAsync({
Expand Down Expand Up @@ -75,7 +81,7 @@ import { MailerModule } from '@tractr/nestjs-mailer';
],
controllers: [FileStorageController],
providers: [
{ provide: APP_GUARD, useClass: JwtGlobalAuthGuard },
{ provide: APP_GUARD, useClass: JwtTwoFactorGuard },
{ provide: APP_GUARD, useClass: PoliciesGuard },
{ provide: APP_INTERCEPTOR, useClass: CaslExceptionInterceptor },
{ provide: APP_INTERCEPTOR, useClass: PrismaExceptionInterceptor },
Expand Down
5 changes: 5 additions & 0 deletions hapify-models.json
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@
"name": "Object",
"properties": [],
"type": "object"
},
{
"name": "otp",
"properties": ["nullable"],
"type": "string"
}
],
"id": "a7d0308a-49f0-3458-0975-1dce106136a1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ export type UserWithIds = <<=getUserFindUniqueReturnTypeFromHapify()>>;
* Get the select configuration for the prisma user query to be able
* to construct the user with the correct ids
*/
export function getSelectPrismaUserQuery(): Prisma.UserSelect {
return <<=getSelectPrismaUserQueryFromHapify()>>;
export function getSelectPrismaUserQuery(user:Partial<Prisma.UserSelect> = {}): Prisma.UserSelect {

const result = <<=getSelectPrismaUserQueryFromHapify()>>;

return {
...result,
...user,
}
}

<<<
Expand Down
18 changes: 15 additions & 3 deletions libs/nestjs/authentication/src/authentication.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import {
AUTHENTICATION_MODULE_OPTIONS,
AUTHENTICATION_USER_SERVICE,
} from './constants';
import { LoginController, PasswordController } from './controllers';
import {
LoginController,
PasswordController,
TwoFactorAuthenticationController,
} from './controllers';
import { AuthenticationOptions } from './dtos';
import { AuthenticationPublicOptions } from './interfaces';
import {
AuthenticationService,
PasswordService,
StrategyOptionsService,
TwoFactorAuthenticationService,
} from './services';
import { AuthenticationUserService } from './services/authentication-user.service';
import { JwtStrategy, LocalStrategy } from './strategies';
import { JwtStrategy, JwtTwoFactorStrategy, LocalStrategy } from './strategies';

import {
AsyncOptions,
Expand Down Expand Up @@ -95,6 +100,7 @@ export class AuthenticationModule extends ModuleOptionsFactory<
],
exports: [
AuthenticationService,
TwoFactorAuthenticationService,
JwtStrategy,
LocalStrategy,
PasswordService,
Expand All @@ -105,16 +111,22 @@ export class AuthenticationModule extends ModuleOptionsFactory<
],
providers: [
AuthenticationService,
TwoFactorAuthenticationService,
PasswordService,
StrategyOptionsService,
JwtStrategy,
JwtTwoFactorStrategy,
LocalStrategy,
{
provide: AUTHENTICATION_USER_SERVICE,
useClass: AuthenticationUserService,
},
],
controllers: [LoginController, PasswordController],
controllers: [
LoginController,
PasswordController,
TwoFactorAuthenticationController,
],
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ export const AUTHENTICATION_DEFAULT_QUERY_PARAM_NAME = 'authToken';
export const DEFAULT_ID_FIELD = 'id';
export const DEFAULT_LOGIN_FIELD = 'email';
export const DEFAULT_PASSWORD_FIELD = 'password';
export const DEFAULT_OTP_FIELD = 'otp';
export const DEFAULT_EMAIL_FIELD = 'email';

export const AUTHENTICATION_USER_SERVICE = 'AUTHENTICATION_USER_SERVICE';

export const TWO_FACTOR_AUTHENTICATION = 'TWO_FACTOR_AUTHENTICATION';

export const DEFAULT_RESET_HTML = `<!DOCTYPE html>
<html lang="en">
<head>
Expand Down
1 change: 1 addition & 0 deletions libs/nestjs/authentication/src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './login.controller';
export * from './password.controller';
export * from './two-factor-authentication.controller';
Loading