Skip to content

Commit

Permalink
feat: JWT 토큰 생성 후 응답 DTO 전달 로직 작성 (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
mybloom committed Jun 9, 2022
1 parent 1c4cc90 commit 4befeb7
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions BE/src/main/java/org/team4/airbnb/auth/OAuthService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 4befeb7

Please sign in to comment.