我一直在挖掘,以便為這個問題找到解決方案。我終于找到了這篇文章:https : //blog.softwaremill.com/who-am-i-keycloak-impersonation-api-bfe7acaf051a??傊?,在我的情況下,我做了:在 Keycloak 中創(chuàng)建服務客戶端(啟用直接訪問授權;啟用服務帳戶):向客戶端添加模擬角色;調用REST API生成中間令牌;# Getting intermediate tokencurl --location --request POST 'http://localhost:8080/auth/realms/MY_REALM/protocol/openid-connect/token' \--header 'Content-Type: application/x-www-form-urlencoded' \--data-urlencode 'client_id=vanilla' \--data-urlencode 'client_secret=c41da386-b4fc-4202-b799-53196284e44f' \--data-urlencode 'grant_type=client_credentials'調用 REST API 將令牌交換為模擬訪問令牌;Impersonated user Access-Tokencurl --location --request POST 'http://localhost:8080/auth/realms/MY_REALM/protocol/openid-connect/token' \--header 'Content-Type: application/x-www-form-urlencoded' \--data-urlencode 'client_id=vanilla' \--data-urlencode 'client_secret=c41da386-b4fc-4202-b799-53196284e44f' \--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \--data-urlencode 'subject_token=<ACCESS_TOKEN_FROM_PREVIOUS_STEP_2> \--data-urlencode 'requested_token_type=urn:ietf:params:oauth:token-type:access_token' \--data-urlencode 'requested_subject=34307875-39a6-4828-8cf0-f59f403bd51f'使用令牌訪問所需的資源;例如curl --location --request GET 'http://localhost:8090/todos' \--header 'Authorization: Bearer <ACCESS_TOKEN_FROM_PREVIOUS_STEP_3>'注意:必須為交換令牌啟用 Keycloak 服務器:未實現(xiàn) Keycloak 模擬 API
1 回答
ITMISS
TA貢獻1871條經驗 獲得超8個贊
您的代碼適用于具有Failure可用變量的Beanshell 斷言
但是對于JSR223 斷言,只需使用以下行:
AssertionResult.setFailure(true);
如果檢測到錯誤,腳本應使用 AssertionResult.setFailureMessage("message") 和 AssertionResult.setFailure(true)。
添加回答
舉報
0/150
提交
取消
