Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #87 from gsainfoteam/idp
Browse files Browse the repository at this point in the history
first commit idp
  • Loading branch information
minjunj authored Jan 20, 2024
2 parents 9ba17b1 + dedfd97 commit 5670901
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Step 1
## base image for Step 1: Node 14
FROM node:14 AS builder
FROM node:18 AS builder
WORKDIR /app
COPY package.json .
COPY package-lock.json .
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@nestjs/platform-express": "^9.0.0",
"@nestjs/typeorm": "^9.0.1",
"@types/passport-jwt": "^3.0.8",
"axios": "^1.4.0",
"axios": "^1.6.5",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"joi": "^17.7.0",
Expand Down
9 changes: 3 additions & 6 deletions src/user/dto/login-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
export class LoginUserDto {
readonly jwt_token : string;

readonly email : string;
readonly code: string;

readonly uuid : string;
}

readonly state?: string;
}
5 changes: 3 additions & 2 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Controller,
Get,
Post,
Query,
Req,
SetMetadata,
UseGuards,
Expand All @@ -15,8 +16,8 @@ import { LoginUserDto } from './dto/login-user.dto';
export class UserController {
constructor(private readonly usersevice: UserService) {}

@Post('/join')
LogIn(@Body() loginuserDto: LoginUserDto): Promise<{ accessToken }> {
@Get('/join') // front-end set this path to redirect url /user/join
LogIn(@Query() loginuserDto: LoginUserDto): Promise<{ accessToken }> {
return this.usersevice.LogIn(loginuserDto); //idp에서 발급받은 jwt token
}

Expand Down
37 changes: 36 additions & 1 deletion src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {
ConflictException,
Inject,
Injectable,
InternalServerErrorException,
NotFoundException,
UnauthorizedException,
} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { JwtService } from '@nestjs/jwt';
Expand All @@ -13,6 +15,8 @@ import { User } from './entity/user.entity';
import { LoginUserDto } from './dto/login-user.dto';
import { PaylaodDto } from './dto/payload.dto';
import { AuthParse } from 'src/utils/utils';
import { AxiosError, AxiosResponse } from 'axios';
import { catchError, firstValueFrom } from 'rxjs';

@Injectable()
export class UserService {
Expand All @@ -27,7 +31,38 @@ export class UserService {
/**idp로 부터 get 요청을 통해 유저의 로그인 여부를 확인합니다.
* 확인되었다면 Gistalk용 jwtToken을 리턴합니다
*/
async LogIn(Loginuserdto: LoginUserDto): Promise<any> {}
async LogIn({ code, state }: LoginUserDto): Promise<any> {
console.log('in login');
console.log(code);
const accessTokeResponse = await firstValueFrom(
this.httpService
.post(
'https://api.idp.gistory.me/oauth/token',
{
code: code,
grant_type: 'authorization_code',
redirect_uri: 'http://localhost:3000/user/join',
},
{
headers: { 'content-type': 'application/x-www-form-urlencoded' },
auth: {
username: this.configService.get<string>('CLIENT_ID'),
password: this.configService.get<string>('CLIENT_SECRET_KEY'),
},
},
)
.pipe(
catchError((err: AxiosError) => {
if (err.response?.status === 401) {
throw new UnauthorizedException('Invalid auth code');
}
throw new InternalServerErrorException('network error');
}),
),
);

return accessTokeResponse.data;
}
}

// let { jwt_token, email, uuid } = Loginuserdto;
Expand Down

0 comments on commit 5670901

Please sign in to comment.