Class OahStateService

java.lang.Object
com.github.catomat0.oauthhelper.oauth.OahStateService

public class OahStateService extends Object
OAuth state + PKCE code_verifier 발급/검증 (CSRF + code injection 방어).

authorize 리다이렉트 전 issue(String) → state 와 code_challenge 반환.

콜백에서 validateAndConsume(String, String) → code_verifier 반환 (token exchange 에 첨부).

같은 state 는 두 번 쓸 수 없다 (원자적 소비).

Redis 저장 값: "{provider}|{codeVerifier}" 형식.

  • Constructor Details

    • OahStateService

      public OahStateService(org.springframework.data.redis.core.RedisTemplate<String,String> redisTemplate, OahProperties properties)
  • Method Details

    • issue

      public OahAuthorizeParams issue(String provider)
      state 와 PKCE code_challenge 를 생성하고 Redis 에 저장 후 반환.

      반환된 값을 authorize URL 쿼리에 붙여야 한다: &state=... &code_challenge=... &code_challenge_method=S256

    • validateAndConsume

      public String validateAndConsume(String state, String expectedProvider)
      state 를 Redis 에서 원자적으로 조회+삭제(GETDEL) 후 provider 일치 여부 확인 → code_verifier 반환.

      false 대신 null 반환 시 CSRF 공격 or 만료 or 재사용 시도로 간주하고 요청 거부.

      요구사항: Redis 6.2 이상.

      Returns:
      code_verifier (PKCE token exchange 에 사용) — 검증 실패 시 null