Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore: ✏️ Modification of Refresh Token Specification #203

Merged
merged 15 commits into from
Nov 15, 2024

Conversation

psychology50
Copy link
Member

작업 이유

  • We had a problem:
    • To handle the stolen refresh token scenario, we apply the RTR technique (saving the user's valid refresh token in Redis).
    • However, if a client accesses the application from multiple devices, the server mistakenly considers the token stolen because the user's valid refresh token in Redis gets overwritten.
  • Therefore, we need to include device_id when creating a refresh token and save it in Redis.

작업 사항

1️⃣ API Specification

  • The client must send device_id in the following scenarios:
    • general & oauth signup
    • general & oauth signin
    • synchronize general with oauth (2 cases)
  • These APIs will now accept additional data.

2️⃣ Append Device Id Field to Refresh Token Entity

@RedisHash("refreshToken")
@Getter
public class RefreshToken {
    @Id
    private String id;
    private Long userId;
    private String deviceId;
    ...
}
  • The RefreshToken entity now includes a deviceId field.
  • To uniquely identify a refresh token, the id is combination of userId and deviceId.

3️⃣ Modify Delete Method in RefreshTokenService

@Repository
@RequiredArgsConstructor
public class RefreshTokenCustomRepositoryImpl implements RefreshTokenCustomRepository {
    private final RedisTemplate<String, String> redisTemplate;

    @Override
    public void deleteAllByUserId(Long userId) {
        String pattern = "refreshToken:" + userId + ":*";
        Set<String> keys = redisTemplate.keys(pattern);

        if (keys != null && !keys.isEmpty()) {
            redisTemplate.delete(keys);
        }
    }
}
  • Previously, we assumed a single refresh token per user.
  • Now, since users can have multiple refresh tokens, all tokens are deleted from Redis when the server detects a stolen token.
  • Although Redis recommends using SCAN for reading multiple values, the number of deviceId matches for a given userId is typically one or two at most.

리뷰어가 중점적으로 확인해야 하는 부분

  • none

발견한 이슈

  • none

@psychology50 psychology50 added the fix 기능 수정 label Nov 15, 2024
@psychology50 psychology50 self-assigned this Nov 15, 2024
@psychology50 psychology50 merged commit 04700fc into dev Nov 15, 2024
1 check passed
@psychology50 psychology50 deleted the fix/add-device-id-info-for-refresh branch November 15, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix 기능 수정
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant