Skip to content

Commit

Permalink
Merge branch 'develop' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
gerry-mandering committed Apr 24, 2024
2 parents aedccec + 4e0ac40 commit 7c58989
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ dependencies {
runtimeOnly "io.jsonwebtoken:jjwt-jackson:0.12.3"

implementation 'com.google.code.gson:gson:2.10.1'
implementation 'jakarta.servlet:jakarta.servlet-api:6.0.0'


implementation 'org.springframework.boot:spring-boot-starter-data-redis:3.2.2'
implementation 'org.springframework.boot:spring-boot-starter-cache:3.2.3'

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.example.dreamvalutbackend.redis.repository.TokenRepository;
import com.google.gson.Gson;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -34,24 +35,29 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo

Map<String, Object> responseMap = principal.getUserInfo();

String accessToken = JwtUtils.generateToken(responseMap, JwtConstants.ACCESS_EXP_TIME);
String refreshToken = JwtUtils.generateToken(responseMap, JwtConstants.REFRESH_EXP_TIME);

responseMap.put("accessToken", JwtUtils.generateToken(responseMap, JwtConstants.ACCESS_EXP_TIME));
responseMap.put("refreshToken", refreshToken);

Long userId = principal.getUserId();
Token token = new Token(refreshToken, userId);
tokenRepository.save(token);


Gson gson = new Gson();
String json = gson.toJson(responseMap);
response.addCookie(createCookie("accessToken", accessToken, JwtConstants.ACCESS_EXP_TIME, true, false));

response.addCookie(createCookie("refreshToken", refreshToken, JwtConstants.REFRESH_EXP_TIME, true, false));

response.setContentType("application/json; charset=UTF-8");
String clientUrl = "http://localhost:3000/genre";
response.sendRedirect(clientUrl);
}

PrintWriter writer = response.getWriter();
writer.println(json);
writer.flush();
private Cookie createCookie(String name, String value, int maxAge, boolean httpOnly, boolean secure) {
Cookie cookie = new Cookie(name, value);
cookie.setMaxAge(maxAge);
cookie.setHttpOnly(httpOnly);
// cookie.setSecure(secure);
cookie.setPath("/");
return cookie;
}

}
Expand Down

0 comments on commit 7c58989

Please sign in to comment.