-
Spring security > 5.1 jwt 인증하는 방법project 2022. 4. 25. 17:32
https://docs.spring.io/spring-security/reference/servlet/oauth2/resource-server/jwt.html
OAuth 2.0 Resource Server JWT :: Spring Security
Most Resource Server support is collected into spring-security-oauth2-resource-server. However, the support for decoding and verifying JWTs is in spring-security-oauth2-jose, meaning that both are necessary in order to have a working resource server that s
docs.spring.io
리소스 서버에서 jwt 로 인증하는 과정을 알아보자.
<Gradle dependency 추가>
implementation 'org.springframework.security:spring-security-oauth2-resource-server:5.6.3'
Authorization server 가 사용자에게 access token 을 발급했다는 가정 하에 인증을 진행한다. (구글 등에서 준 OAuth2 access token 을 받아서 쓴다는 이야기가 아니란 거에 주의하자.)
인증 과정은 다음과 같다.
1. Filter 에서 request 로 부터 access token 을 꺼낸다.
2. Converter 를 이용해 Authentication Token 을 생성한다.
3. Authentication Manager 에게 Authentication Token 을 이용해 인증을 요청한다.
4. Authentication 을 리턴하면 security context 에 넣고 인증을 완료한다.
위의 과정을 .oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt); 설정만으로 default 옵션으로 사용할 수도 있고, 원하는 부분을 override 해서 customizing 할 수 있다.
* Authorization server 는 spring security 에서 지원하지 않는 기능이다. 따라서 스스로 구현해야 한다. (ㅇㄴㅇ!)Sub-project로 지원한다고 한다.
'project' 카테고리의 다른 글
Spring security 5 OAuth2 공부한거 (0) 2022.05.06 테스트 코드의 중요성, TDD (0) 2022.04.30 spring security oauth2 로그인 구현 (개발 로그) (0) 2022.03.30 Spring Db, jpa 를 사용하며 고민들 (0) 2022.03.29 협업 준비 (백엔드, 인프라) (0) 2022.02.02