Skip to content

Commit

Permalink
[FIX] 소셜로그인 API 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
unanchoi committed Jan 16, 2024
1 parent a2fc6cd commit a7c8c2c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
2 changes: 1 addition & 1 deletion http/application/get-application-page1.http
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// get from http-client.private.env.json
GET {{host}}/api/application/1/page1
Authorization: Bearer {{token}}
Authorization: Bearer {{new-token}}
2 changes: 2 additions & 0 deletions http/application/get-applications.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GET {{host}}/api/application
Authorization: Bearer {{token}}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.startlion.startlionserver.config.jwt;

import com.startlion.startlionserver.domain.entity.User;
import io.jsonwebtoken.*;
import io.jsonwebtoken.security.Keys;
import jakarta.annotation.PostConstruct;
Expand Down Expand Up @@ -31,22 +30,11 @@ protected void init() {

public String generateToken(Authentication authentication, Long tokenExpirationTime) {
final Date now = new Date();
User user = (User) authentication.getPrincipal();

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

// refreshToken을 제외한 필드만 가진 객체 생성
Map<String, Object> claims = new HashMap<>();
claims.put("id", user.getUserId());
claims.put("createdAt", user.getCreatedAt().format(formatter));
claims.put("updatedAt", user.getUpdatedAt().format(formatter));
claims.put("userId", user.getUserId());
claims.put("email", user.getEmail());
claims.put("username", user.getUsername());
claims.put("socialId", user.getSocialId());
claims.put("imageUrl", user.getImageUrl());
claims.put("expiredIn", user.getExpiredIn());

claims.put("id", authentication.getPrincipal());


return Jwts.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public OAuthResponse authenticateUser(String authCode) throws Exception {
jsonNode.get("picture").asText());

User user = userRepository.findByEmail(email).orElseGet(() -> userRepository.save(newUser));
val authentication = new UsernamePasswordAuthenticationToken(user, null, null);
val authentication = new UsernamePasswordAuthenticationToken(user.getUserId(), null, null);
val tokenVO = generateToken(authentication);
user.updateRefreshToken(tokenVO.refreshToken());
return OAuthResponse.of(tokenVO.accessToken(), tokenVO.refreshToken());
Expand Down

0 comments on commit a7c8c2c

Please sign in to comment.