From 4befeb797e4485860c8bc8129d96543b64cbe9c1 Mon Sep 17 00:00:00 2001 From: mybloom Date: Thu, 9 Jun 2022 22:22:33 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20JWT=20=ED=86=A0=ED=81=B0=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=ED=9B=84=20=EC=9D=91=EB=8B=B5=20DTO=20=EC=A0=84?= =?UTF-8?q?=EB=8B=AC=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1=20(ios-h/ai?= =?UTF-8?q?rbnb#35)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/team4/airbnb/auth/OAuthService.java | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/BE/src/main/java/org/team4/airbnb/auth/OAuthService.java b/BE/src/main/java/org/team4/airbnb/auth/OAuthService.java index bcaaa3db1..1353ed062 100644 --- a/BE/src/main/java/org/team4/airbnb/auth/OAuthService.java +++ b/BE/src/main/java/org/team4/airbnb/auth/OAuthService.java @@ -1,12 +1,7 @@ package org.team4.airbnb.auth; -import io.jsonwebtoken.Header; -import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.SignatureAlgorithm; import java.nio.charset.StandardCharsets; -import java.time.Duration; import java.util.Collections; -import java.util.Date; import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.core.ParameterizedTypeReference; @@ -52,35 +47,20 @@ public LoginResponse processLogin(String provider, String authCode) { Customer findCustomer = customerRepository.findByUserId(userIdViaUserProfile) .orElse(null); - if(findCustomer == null) { + if (findCustomer == null) { customer = customerRepository.save(customer); } - //4. JWT 토큰 생성 후 전달 - String jwtToken = makeJwtToken(userIdViaUserProfile); + //4. JWT 토큰 생성 후 응답 DTO 전달 + JwtTokenProvider jwtTokenProvider = new JwtTokenProvider(); + String accessToken = jwtTokenProvider.createAccessToken(userIdViaUserProfile); + String refreshToken = jwtTokenProvider.createRefreshToken(); - return null; - } + LoginResponse loginResponse = LoginResponse.of(accessToken, refreshToken, "Bearer"); - private String makeJwtToken(String userId){ - long currentTime = System.currentTimeMillis(); - Date now = new Date(); - - String jwtToken = Jwts.builder() - .setHeaderParam(Header.TYPE, Header.JWT_TYPE) //Header 셋팅 : 토큰 타입 정보 typ - //payload - registered claim 셋팅 - .setIssuer("team4") //iss - .setIssuedAt(new Date(currentTime)) //iat - .setExpiration(new Date(now.getTime() + Duration.ofMillis(30).toMillis())) //exp - //payload - private claim - .claim("userId",userId) - .signWith(SignatureAlgorithm.HS256, "keySecret") //해싱알고리즘, 시크릿키 - .compact(); - - return jwtToken; + return loginResponse; } - private OauthTokenResponse getAccessTokenFromOauth(String authCode, OauthProvider oauthProvider) { OauthTokenResponse oauthTokenResponse = WebClient.create()