JWT(JSON Web Token) 구조
- 점(.)으로 구분된 다음 순차적인 세 개의 Base64URL 인코딩된 문자열로 구성
- 헤더
- 페이로드
- 서명
String jwt = "ey...";
assertThat(actual).satisfies(s->{
String[] parts = s.split("\\.");
assertThat(parts).hasSize(3);
assertThat(parts[0]).matches(s1 ->{
new ObjectMapper().readTree(Base64.getUrlDecoder().decode(s1));
})
assertThat(parts[1]).matches(s1 ->{
new ObjectMapper().readTree(Base64.getUrlDecoder().decode(s1));
})
assertThat(parts[2]).matches(s1 ->{
Base64.getUrlDecoder().decode(s1);
})
})
jwt만들기
Jwts
.builder()
.signWith(new SecretKeySpec(jwtSecret.getBytes(),"HmacSHA256"))
.compact()