개인적으로 SSO 한번써보기 참 힘들다..
소셜로그인을 진행했을 때 SSO를 이용하는 다른 서버에서 SSO로 로그인 요청을 해야했고 이때는 소셜로그인 시 발급되는 uuid정도만 사용해서 토큰 발급을 받아야 했다.
keycloak api 커스텀을 해야하는지 고민을 하던 중 다행히도 방법을 찾게 되었다. (역시 도큐먼트를 잘봐야..)
먼저 시작부터 막히게 되었다.
도큐먼트에는 떡하니 Permissions 탭이 존재하는데
나의 keycloak에는..?
다행히 구글링을 통해 특정버전 이후로부터 이러한 설정들이 숨겨지게 되었다는 것을 알게되어
해당 설정을 추가해서 다시 실행하니 사라진 Permissions 탭이 등장하였다
# keycloak 폴더에서
vi standalone/configuration/profile.properties
# 입력
feature.admin_fine_grained_authz=enabled
feature.token_exchange=enabled
# 재실행
나머지는 위의 링크대로 진행한 결과 유저 아이디와 클라이언트 값만으로 토큰을 발급받을 수 있게 되었다!
payload=f'client_id={CLIENT_ID}&client_secret={CLIENT_SECRET}&requested_subject={username}&grant_type=urn:ietf:params:oauth:grant-type:token-exchange'.encode('utf-8')
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.request("POST", TOKEN_ENDPOINT, headers=headers, data=payload)
{"access_token":"token","expires_in":300,"refresh_expires_in":1800,"refresh_token":"token","token_type":"Bearer","not-before-policy":0,"session_state":"-","scope":"profile email"}