안녕하세요...
현재 Springboot를 이용하여 Oauth2 서버를 구축중입니다...
구성은
* AuthorizationServer <--> Login Server
* ResourceServer(API)
로 되어있고
AuthorizationServer로 엑세스 토큰 요청시 로그인 서버에서 로그인 후 사용자 상세정보를 리턴받아
최종 ResourceServer에서 Principal 객체에서 해당 사용자 상세 정보를 끄집어내어 사용하고자 합니다.
해서 처리한 방법은 아래와 같습니다.
로그인 서버에서 로그인 후
public class CustomAuthenticationProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
CustomUser user = (CustomUser) userDetailsService.loadUserByUsername(username);
~~~blah~blah~~
return new UsernamePasswordAuthenticationToken(user, password, authorities);
}
위 처럼 CustomUser 객체를 받아 AuthorizationServer로 응답을 해주고 있습니다.
이 후 발급받은 토큰을 이용하여 ResourceServer에서 Principal 객체를 출력해 보면 아래와 같이 데이터가 출력됩니다.
이중 userAuthentication을 이용해서 토큰 사용자의 부가데이터를 이용해서 서비스를 진행하려고 하는데
{
"authorities": [
{
"authority": "USER"
}
],
"details": {
"remoteAddress": "127.0.0.1",
"sessionId": "4B7C6FBB1F87E41D451483BD74E4ED6B",
"tokenValue": "~~~~TOKEN~~~~",
"tokenType": "Bearer",
"decodedDetails": null
},
"authenticated": true,
"userAuthentication": {
"authorities": [
{
"authority": "USER"
}
],
"details": null,
"authenticated": true,
"principal": "USER-ID",
"credentials": "N/A",
"name": "USER-ID"
},
"clientOnly": false,
"oauth2Request": {
"clientId": "my_client_id",
"scope": [
"member.info.public"
],
~~~~
userAuthentication 쪽에 details 나 기타 필드를 추가?/가공? 을 하면 될거 같은데 찾기가 힘드네요..^^;;
도움을 주실 수 있는지 문의 드립니다.
아니면 처음부터 리소스서버에서 사용자의 상세 정보를 사용하는 위 방법 자체가 잘못된 것인지 잘 모르겠네요..^^;;
기본적으로 토큰발급시 저장된 사용자 ID만을 가지고 리소스 서버에서 처리해야 하는것 맞는건지...;;
(그렇게 되면 매 API 호출시 마다 사용자 상세 정보를 뒤져야 하기에(이게 맞나요?^^;;;)
도움 부탁드립니다~~~