Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { JwtAccessStrategy } from './infrastructure/jwt/jwt-access.strategy';
import { JwtProvider } from './infrastructure/jwt/jwt.provider';
import { PassportModule } from '@nestjs/passport';
import { JwtModule } from '@nestjs/jwt';
import { OAuthProviderFactory } from 'src/auth/core/infrastructure/oauth/oauth-provider.factory';
import { KakaoOAuthProvider } from './infrastructure/oauth/kakao.provider';
import { OAuthProviderFactory } from './infrastructure/oauth/oauth-provider.factory';

const jwt = [JwtProvider, JwtAccessStrategy, JwtRefreshStrategy];
const oAuth = [OAuthProviderFactory, KakaoOAuthProvider];

@Module({
imports: [PassportModule, JwtModule.register({})],
providers: [...jwt, OAuthProviderFactory, KakaoOAuthProvider],
providers: [...jwt, ...oAuth],
controllers: [],
exports: [OAuthProviderFactory, ...jwt],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OAuthProviderType } from 'src/auth/auth-user/domain/value-object/oauth-provider.enum';
import { OAuthProviderType } from 'iam/auth/auth-user/domain/value-object/oauth-provider.enum';

export interface BaseOAuthProvider {
getToken(code: string): Promise<string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable, UnauthorizedException } from '@nestjs/common';
import axios from 'axios';
import { ConfigService } from '@nestjs/config';
import { BaseOAuthProvider, OAuthUser } from './base-oauth.provider';
import { OAuthProviderType } from 'src/auth/auth-user/domain/value-object/oauth-provider.enum';
import { OAuthProviderType } from 'iam/auth/auth-user/domain/value-object/oauth-provider.enum';

interface KakaoTokenResponse {
access_token: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { BaseOAuthProvider } from './base-oauth.provider';
import { KakaoOAuthProvider } from './kakao.provider';
import { OAuthProviderType } from 'src/auth/auth-user/domain/value-object/oauth-provider.enum';
import { OAuthProviderType } from 'iam/auth/auth-user/domain/value-object/oauth-provider.enum';

@Injectable()
export class OAuthProviderFactory {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class CheckAccountIdCommand {
constructor(public readonly accountId: string) {}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Inject, Injectable } from '@nestjs/common';
import { AUTH_ORGANIZATION_STORE, AuthOrganizationStore } from '../../domain/auth-organization.store';
import { CommandHandler } from '@nestjs/cqrs';
import { CheckAccountIdCommand } from './check-account-id.command';

@Injectable()
@CommandHandler(CheckAccountIdCommand)
export class CheckAccountIdUseCase {
constructor(
@Inject(AUTH_ORGANIZATION_STORE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { ICommand } from '@nestjs/cqrs';

export class CreateAuthOrganizationCommand implements ICommand {
export class CreateAuthOrganizationCommand {
constructor(
public readonly accountId: string,
public readonly password: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { ICommand } from '@nestjs/cqrs';

export class LoginCommand implements ICommand {
export class LoginCommand {
constructor(
public readonly accountId: string,
public readonly password: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsNotEmpty, IsString } from 'class-validator';

export class LoginResponseDto {
export class LoginResult {
@IsString()
@IsNotEmpty()
accessToken: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Inject, Injectable } from '@nestjs/common';
import { CommandHandler } from '@nestjs/cqrs';
import { LoginCommand } from './login.command';
import { AUTH_ORGANIZATION_STORE, AuthOrganizationStore } from '../../domain/auth-organization.store';
import { PASSWORD_HASHER, PasswordHasher } from '../../domain/password-hasher';
import { CustomException } from 'src/shared/exception/custom-exception';
import { CustomExceptionCode } from 'src/shared/exception/custom-exception-code';
import { JwtProvider } from 'src/auth/core/infrastructure/jwt/jwt.provider';
import { TokenType } from 'src/auth/core/infrastructure/jwt/jwt.factory';
import { LoginResponseDto } from './dto/login.response.dto';
import { AuthOrganization } from '../../domain/auth-organization';
import { Role } from 'src/auth/core/domain/value-object/role';
import { LoginResult } from './login.result';
import { JwtProvider } from 'iam/auth/auth-core/infrastructure/jwt/jwt.provider';
import { Role } from 'iam/auth/auth-core/domain/value-object/role';
import { TokenType } from 'iam/auth/auth-core/infrastructure/jwt/jwt.factory';

@Injectable()
@CommandHandler(LoginCommand)
export class LoginUseCase {
constructor(
@Inject(AUTH_ORGANIZATION_STORE)
Expand All @@ -22,7 +20,7 @@ export class LoginUseCase {
private readonly jwtProvider: JwtProvider,
) {}

async execute(command: LoginCommand): Promise<LoginResponseDto> {
async execute(command: LoginCommand): Promise<LoginResult> {
const { accountId, password } = command;

const authOrganization = await this.validateAccount(accountId.trim(), password.trim());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class LogoutCommand {
constructor(public readonly organizationId: string) {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { ICommand } from '@nestjs/cqrs';

export class RenewTokenCommand implements ICommand {
export class RenewTokenCommand {
constructor(
public readonly organizationId: string,
public readonly jti: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsNotEmpty, IsString } from 'class-validator';

export class RenewTokenResponseDto {
export class RenewTokenResult {
@IsString()
@IsNotEmpty()
accessToken: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import { Inject, Injectable } from '@nestjs/common';
import { JwtProvider } from 'src/auth/core/infrastructure/jwt/jwt.provider';
import { AUTH_ORGANIZATION_STORE, AuthOrganizationStore } from '../../domain/auth-organization.store';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { RenewTokenCommand } from './renew-token.command';
import { TokenType } from 'src/auth/core/infrastructure/jwt/jwt.factory';
import { CustomException } from 'src/shared/exception/custom-exception';
import { CustomExceptionCode } from 'src/shared/exception/custom-exception-code';
import { RenewTokenResponseDto } from './dto/renew-token.response.dto';
import { AuthOrganization } from '../../domain/auth-organization';
import { Role } from 'src/auth/core/domain/value-object/role';
import { RenewTokenResult } from './renew-token.response.dto';
import { JwtProvider } from 'iam/auth/auth-core/infrastructure/jwt/jwt.provider';
import { TokenType } from 'iam/auth/auth-core/infrastructure/jwt/jwt.factory';
import { Role } from 'iam/auth/auth-core/domain/value-object/role';

@Injectable()
@CommandHandler(RenewTokenCommand)
export class RenewTokenUseCase implements ICommandHandler<RenewTokenCommand> {
export class RenewTokenUseCase {
constructor(
@Inject(AUTH_ORGANIZATION_STORE)
private readonly authOrganizationStore: AuthOrganizationStore,
private readonly jwtProvider: JwtProvider,
) {}

async execute(command: RenewTokenCommand): Promise<RenewTokenResponseDto> {
async execute(command: RenewTokenCommand): Promise<RenewTokenResult> {
const { organizationId, jti } = command;

const authOrganization = await this.validateRefreshToken(organizationId, jti);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Module } from '@nestjs/common';
import { SharedModule } from 'src/shared/shared.module';
import { AuthOrganizationController } from './presentation/auth-organization.controller';
import { AUTH_ORGANIZATION_STORE } from './domain/auth-organization.store';
import { AuthOrganizationStoreImpl } from './infrastructure/auth-organization.store.impl';
import { AuthCoreModule } from '../core/auth-core.module';
import { AuthOrganizationEntity } from './infrastructure/auth-organization.entity';
import { CreateAuthOrganizationUseCase } from './application/create/create.use-case';
import { CqrsModule } from '@nestjs/cqrs';
import { PASSWORD_HASHER } from './domain/password-hasher';
import { AuthOrganizationStoreImpl } from './infrastructure/auth-organization.store.impl';
import { PasswordHasherImpl } from './infrastructure/password-hasher.impl';
import { AuthCoreModule } from '../auth-core/auth-core.module';
import { CheckAccountIdUseCase } from './application/check-account-id/check-account-id.use-case';
import { RenewTokenUseCase } from './application/renew-token/renew-token.use-case';
import { LogoutUseCase } from './application/logout/logout.use-case';
import { LoginUseCase } from './application/login/login.use-case';
import { CheckAccountIdUseCase } from './application/check-account-id/check-account-id.use-case';
import { LogoutUseCase } from './application/logout/logout.use-case';
import { AuthOrganizationController } from './presentation/auth-organization.controller';

const usecases = [CreateAuthOrganizationUseCase, RenewTokenUseCase, LoginUseCase, LogoutUseCase, CheckAccountIdUseCase];

@Module({
imports: [SharedModule, MikroOrmModule.forFeature([AuthOrganizationEntity]), AuthCoreModule, CqrsModule],
providers: [
...usecases,
{
provide: AUTH_ORGANIZATION_STORE,
useClass: AuthOrganizationStoreImpl,
Expand All @@ -28,7 +29,6 @@ const usecases = [CreateAuthOrganizationUseCase, RenewTokenUseCase, LoginUseCase
provide: PASSWORD_HASHER,
useClass: PasswordHasherImpl,
},
...usecases,
],
controllers: [AuthOrganizationController],
exports: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BaseDomainEvent } from 'src/shared/core/domain/base.domain-event';

export class AuthOrganizationCreatedEvent implements BaseDomainEvent {
readonly timesstamp: Date;
readonly timestamp: Date;

constructor(
public readonly organizationId: string,
public readonly name: string,
public readonly contact: string,
) {
this.timesstamp = new Date();
this.timestamp = new Date();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { CheckAccountIdUseCase } from '../application/check-account-id/check-acc
import { CheckAccountIdResponseDto } from './dto/response/check-account-id.response.dto';
import { Organization, OrganizationPayload } from 'src/shared/core/presentation/organization.decorator';
import { Roles } from 'src/shared/core/presentation/role.decorator';
import { RolesGuard } from 'src/auth/core/infrastructure/guard/role.guard';
import { Role } from 'src/auth/core/domain/value-object/role';
import { Role } from 'iam/auth/auth-core/domain/value-object/role';
import { RolesGuard } from 'iam/auth/auth-core/infrastructure/guard/role.guard';

@ApiTags('auth-organization')
@Controller('auth/organization')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IsEnum, IsNotEmpty, IsString } from 'class-validator';
import { OAuthProviderType } from 'src/auth/auth-user/domain/value-object/oauth-provider.enum';
import { OAuthProviderType } from '../../domain/value-object/oauth-provider.enum';

export class AuthorizeOAuthRequestDto {
export class AuthorizeOAuthCommand {
@IsEnum(OAuthProviderType)
@IsNotEmpty()
oAuthProviderType: OAuthProviderType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsUrl } from 'class-validator';

export class AuthorizeOAuthResponseDto {
export class AuthorizeOAuthResult {
@IsUrl()
authUrl: string;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Injectable } from '@nestjs/common';
import { OAuthProviderFactory } from 'src/auth/core/infrastructure/oauth/oauth-provider.factory';
import { AuthorizeOAuthRequestDto } from './dto/authorize-oauth.request.dto';
import { AuthorizeOAuthResponseDto } from './dto/authorize-oauth.response.dto';
import { AuthorizeOAuthCommand } from './authorize-oauth.command';
import { AuthorizeOAuthResult } from './authorize-oauth.result';
import { OAuthProviderFactory } from 'iam/auth/auth-core/infrastructure/oauth/oauth-provider.factory';

@Injectable()
export class AuthorizeOAuthUseCase {
constructor(private readonly oAuthProviderFactory: OAuthProviderFactory) {}

execute(requestDto: AuthorizeOAuthRequestDto): AuthorizeOAuthResponseDto {
const { oAuthProviderType, redirectUrl } = requestDto;
execute(command: AuthorizeOAuthCommand): AuthorizeOAuthResult {
const { oAuthProviderType, redirectUrl } = command;
const provider = this.oAuthProviderFactory.getProvider(oAuthProviderType);

const encodedState = encodeURIComponent(redirectUrl || '');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsNotEmpty, IsString } from 'class-validator';

export class LogoutRequestDto {
export class LogoutCommand {
@IsString()
@IsNotEmpty()
userId: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Inject, Injectable } from '@nestjs/common';
import { LogoutRequestDto } from './dto/logout.request.dto';
import { CustomException } from 'src/shared/exception/custom-exception';
import { CustomExceptionCode } from 'src/shared/exception/custom-exception-code';
import { AUTH_USER_REPOSITORY, AuthUserRepository } from '../../domain/auth-user.repository';
import { AUTH_USER_STORE, AuthUserStore } from '../../domain/auth-user.repository';
import { LogoutCommand } from './logout.command';

@Injectable()
export class LogoutUseCase {
constructor(
@Inject(AUTH_USER_REPOSITORY)
private readonly authRepository: AuthUserRepository,
@Inject(AUTH_USER_STORE)
private readonly authRepository: AuthUserStore,
) {}

async execute(requestDto: LogoutRequestDto): Promise<void> {
const { userId } = requestDto;
async execute(command: LogoutCommand): Promise<void> {
const { userId } = command;
const auth = await this.authRepository.findByUserId(userId);
if (!auth) throw new CustomException(CustomExceptionCode.AUTH_INFO_NOT_FOUND);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { OAuthProviderType } from '../../domain/value-object/oauth-provider.enum';

export class OAuthLoginCommand {
constructor(
public readonly oAuthProviderType: OAuthProviderType,
public readonly code: string,
public readonly state?: string,
) {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsNotEmpty, IsString } from 'class-validator';

export class OAuthLoginResponseDto {
export class OAuthLoginResult {
@IsString()
@IsNotEmpty()
accessToken: string;
Expand Down
Loading
Loading