2.13、配置角色:点击用户编辑页面的角色映射,点击分配角色
可以看到存在同名的角色,但是实际前缀会根据客户端进行标注,注意别选错,勾选后点击赋予即可,这样
2.14、以上配置后,4A平台的配置工作就完成了,客户端、用户、角色权限分配这些动作,都是通用的,不同厂商的oauth2平台虽然页面有区别,但是核心的操作步骤是一致的。接下来就可以在零信任侧进行对接配置了
3、keycloak-oauth2认证接口文档
正常项目中,需要客户/4A平台提供认证接口文档,零信任需要根据接口文档要求的参数配置对接
部分参数说明:
{realm-name}=领域名,注意替换
client_id=4A平台中客户端配置中获取
client_secret=4A平台中客户端配置中获取
API接口说明:
获取code接口:/realms/{realm-name}/protocol/openid-connect/auth
请求示例:
GET /authorize?
response_type=code
&scope=openid%20profile%20email
&client_id=s6BhdRkqt3
&state=af0ifjsldkj
&redirect_uri=https%3A%2F%2Fclient.example.org%2Fcb HTTP/1.1
Host: server.example.com
响应示例:
HTTP/1.1 302 Found
code=SplxlOBeZQQYbYS6WxSbIA
&state=af0ifjsldkj
获取token接口:/realms/{realm-name}/protocol/openid-connect/token
请求示例:
POST /token HTTP/1.1
Host: server.example.com
Content-Type: application/x-www-form-urlencoded
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA
&redirect_uri=https%3A%2F%2Fclient.example.org%2Fcb
响应示例:
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{
"access_token": "SlAV32hkKG",
"token_type": "Bearer",
"refresh_token": "8xLOxBtZp8",
"expires_in": 3600,
"id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjFlOWdkazcifQ.ewogImlzc
yI6ICJodHRwOi8vc2VydmVyLmV4YW1wbGUuY29tIiwKICJzdWIiOiAiMjQ4Mjg5
NzYxMDAxIiwKICJhdWQiOiAiczZCaGRSa3F0MyIsCiAibm9uY2UiOiAibi0wUzZ
fV3pBMk1qIiwKICJleHAiOiAxMzExMjgxOTcwLAogImlhdCI6IDEzMTEyODA5Nz
AKfQ.ggW8hZ1EuVLuxNuuIJKX_V8a_OMXzR0EHR9R6jgdqrOOF4daGU96Sr_P6q
Jp6IcmD3HP99Obi1PRs-cwh3LO-p146waJ8IhehcwL7F09JdijmBqkvPeB2T9CJ
NqeGpe-gccMg4vfKjkM8FcGvnzZUN4_KSP0aAp1tOJ1zZwgjxqGByKHiOtX7Tpd
QyHE5lcMiKPXfEIQILVq0pc_E2DzL7emopWoaoZTF_m0_N0YzFC6g6EJbOEoRoS
K5hoDalrcvRYLSrQAZZKflyuVCyixEoV9GfNQC3_osjzw2PAithfubEEBLuVVk4
XUVrWOLrLl0nx7RkKU8NXNHq-rvKMzqg"
}
获取用户信息接口:/realms/{realm-name}/protocol/openid-connect/userinfo
请求示例:
GET /userinfo HTTP/1.1
Host: server.example.com
Authorization: Bearer SlAV32hkKG
响应示例:
HTTP/1.1 200 OK
Content-Type: application/json
{
"sub": "248289761001",
"name": "Jane Doe",
"given_name": "Jane",
"family_name": "Doe",
"preferred_username": "j.doe",
"email": "janedoe@example.com",
"picture": "http://example.com/janedoe/me.jpg"
}