Keycloak OpenID Connect
Keycloak 설정
Client 생성
- Clients 탭
Create Client
- General Settings
- Client type:
OpenID Connect
- Client ID:
<clientID>
- Client type:
- Capability config
- Client authenticatoion:
On
(secret
orjwt
orsecret-jwt
중 하나로 클라이언트 인증을 수행하는 기능) - Authorization:
Off
(keycloak의 정책을 통해 접근 제어를 수행하는 기능) - Authentication flow
Standard flow
Direct access grants
- Client authenticatoion:
- General Settings
<clientID>
선택- Settings
- Enabled:
On
- Valid Redirect URIs
https://*
- 가능한 좁은 범위로 설정하는 것이 좋습니다
- Enabled:
- Credentials
- Client Authenticator:
Client ID and Secret
- Client Secret:
<clientSecret>
- Client Authenticator:
- Settings
groups clinet scope 생성
- Client Scopes 탭
Create client scope
- Name:
groups
- Protocol:
OpenID Connect
- Include in token scope:
On
- JWT scope에 groups가 추가됩니다.
- Name:
groups
선택- Mappers
Configure a new mapper
Group Membership
선택- Name:
groups
- Token Claim Name:
groups
- Full group path:
Off
- Add to ID token:
On
- Add to access token:
On
- Name:
- Mappers
Access/ID Token 설정
- Clients 탭
<clientID>
선택- Client Scopes
<clientID>-dedicated
선택- 해당 클라이언트 전용 설정입니다.
Configure a new mapper
Audience
선택- Name:
audience
- Included Client Audience:
<clientID>
- Add to ID token:
On
- Add to access token:
On
- Name:
Add client scope
groups
Add
:Default
email
- Default
- Client Scopes
Test
curl -k -X POST https://<keycloak-url>/realms/<realm>/protocol/openid-connect/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=<clientID>" \
-d "client_secret=<clientSecret>" \
-d "scope=openid" \
-d "grant_type=password" \
-d "username=<user>" \
-d "password=<password>" \
-d "totp=<otp>" \
| jq '.'
테스트를 통해 토큰을 획득한 후, 어떤 정보가 들어있는지 https://jwt.io/ 에서 확인해보는 것이 좋습니다.
클라이언트 연결
- Issuer URL:
https://<keycloak-url>/realms/<realm>
- Client ID:
<clientID>
- Client Secret:
<clientSecret>
- Username claim
email
이 많이 사용됩니다.- email을 사용하는 경우
email_verified
를 확인하는 애플리케이션이 있습니다.
- Groups claim:
groups
가 많이 사용됩니다.