-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
72 changed files
with
2,863 additions
and
411 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,6 @@ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | |
|
||
# vscode setting | ||
.vscode | ||
|
||
# remote | ||
.remote |
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,13 +1,23 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { PassportModule } from '@nestjs/passport'; | ||
import { GoogleAuthController } from '@/auth/google/googleAuth.controller'; | ||
import { GoogleAuthService } from '@/auth/google/googleAuth.service'; | ||
import { GoogleStrategy } from '@/auth/google/strategy/google.strategy'; | ||
import { SessionSerializer } from '@/auth/session/session.serializer'; | ||
import { TesterStrategy } from '@/auth/tester/strategy/tester.strategy'; | ||
import { TesterAuthController } from '@/auth/tester/testerAuth.controller'; | ||
import { TesterAuthService } from '@/auth/tester/testerAuth.service'; | ||
import { UserModule } from '@/user/user.module'; | ||
|
||
@Module({ | ||
imports: [UserModule], | ||
controllers: [GoogleAuthController], | ||
providers: [GoogleStrategy, GoogleAuthService, SessionSerializer], | ||
imports: [UserModule, PassportModule.register({ session: true })], | ||
controllers: [GoogleAuthController, TesterAuthController], | ||
providers: [ | ||
GoogleStrategy, | ||
GoogleAuthService, | ||
SessionSerializer, | ||
TesterAuthService, | ||
TesterStrategy, | ||
], | ||
}) | ||
export class AuthModule {} |
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
30 changes: 30 additions & 0 deletions
30
packages/backend/src/auth/session/websocketSession.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,30 @@ | ||
import { MemoryStore } from 'express-session'; | ||
import { Socket } from 'socket.io'; | ||
import { websocketCookieParse } from '@/auth/session/cookieParser'; | ||
import { PassportSession } from '@/auth/session/webSocketSession.guard'; | ||
|
||
export class WebsocketSessionService { | ||
constructor(private readonly sessionStore: MemoryStore) {} | ||
|
||
async getAuthenticatedUser(socket: Socket) { | ||
try { | ||
const cookieValue = websocketCookieParse(socket); | ||
const session = await this.getSession(cookieValue); | ||
return session ? session.passport.user : null; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
|
||
private getSession(cookieValue: string) { | ||
return new Promise<PassportSession | null>((resolve) => { | ||
this.sessionStore.get(cookieValue, (err: Error, session) => { | ||
if (err || !session) { | ||
resolve(null); | ||
} | ||
resolve(session as PassportSession); | ||
}); | ||
}); | ||
} | ||
} |
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 { ExecutionContext, Injectable } from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
|
||
@Injectable() | ||
export class TestAuthGuard extends AuthGuard('local') { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
async canActivate(context: ExecutionContext) { | ||
const isActivate = (await super.canActivate(context)) as boolean; | ||
const request = context.switchToHttp().getRequest(); | ||
await super.logIn(request); | ||
return isActivate; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/backend/src/auth/tester/strategy/tester.strategy.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,16 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { PassportStrategy } from '@nestjs/passport'; | ||
import { Strategy } from 'passport-local'; | ||
import { TesterAuthService } from '@/auth/tester/testerAuth.service'; | ||
|
||
@Injectable() | ||
export class TesterStrategy extends PassportStrategy(Strategy) { | ||
constructor(private readonly testerAuthService: TesterAuthService) { | ||
super(); | ||
} | ||
|
||
async validate(username: string, password: string, done: CallableFunction) { | ||
const user = await this.testerAuthService.attemptAuthentication(); | ||
done(null, user); | ||
} | ||
} |
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,51 @@ | ||
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common'; | ||
import { | ||
ApiOkResponse, | ||
ApiOperation, | ||
ApiQuery, | ||
ApiTags, | ||
} from '@nestjs/swagger'; | ||
import { Request, Response } from 'express'; | ||
import { TestAuthGuard } from '@/auth/tester/guard/tester.guard'; | ||
|
||
@ApiTags('Auth') | ||
@Controller('auth/tester') | ||
export class TesterAuthController { | ||
constructor() {} | ||
|
||
@ApiOperation({ | ||
summary: '테스터 로그인 api', | ||
description: '테스터로 로그인합니다.', | ||
}) | ||
@ApiQuery({ | ||
name: 'username', | ||
required: true, | ||
description: '테스터 아이디(값만 넣으면 됨)', | ||
}) | ||
@ApiQuery({ | ||
name: 'password', | ||
required: true, | ||
description: '테스터 비밀번호(값만 넣으면 됨)', | ||
}) | ||
@Get('/login') | ||
@UseGuards(TestAuthGuard) | ||
async handleLogin(@Res() response: Response) { | ||
response.redirect('/'); | ||
} | ||
|
||
@ApiOperation({ | ||
summary: '로그인 상태 확인', | ||
description: '로그인 상태를 확인합니다.', | ||
}) | ||
@ApiOkResponse({ | ||
description: '로그인된 상태', | ||
example: { message: 'Authenticated' }, | ||
}) | ||
@Get('/status') | ||
async user(@Req() request: Request) { | ||
if (request.user) { | ||
return { message: 'Authenticated' }; | ||
} | ||
return { message: 'Not Authenticated' }; | ||
} | ||
} |
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,11 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { UserService } from '@/user/user.service'; | ||
|
||
@Injectable() | ||
export class TesterAuthService { | ||
constructor(private readonly userService: UserService) {} | ||
|
||
async attemptAuthentication() { | ||
return await this.userService.registerTester(); | ||
} | ||
} |
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
Oops, something went wrong.