(O+P)ut

アウトプット



(O+P)ut

エンジニアのアウトプット

【Keycloak/RHBK】AdminAPIでクライアントリソースを新規作成する

スポンサーリンク

やりたいこと

Red Hat build of Keycloak(Keycloakの商用版)にてAdmin API経由でクライアントリソース(client resource)を作成する。

環境情報
  • Red Hat Enterprise Linux : 9.3 (Plow)
  • rhbk-22.0.8

やり方

アクセストークン及びリソースを作成したいクライアントのIDを用意した上で以下のようにPOSTを行う。

$ curl --location --request POST 'http://localhost:8080/admin/realms/master/clients/XX/authz/resource-server/resource' --header 'Content-Type: application/json' --header "Authorization: Bearer $AT" --data-raw '{"name":"test_resource","displayName":"testr","type":"","scopes":[],"icon_uri":"","ownerManagedAccess":false,"uris":["/test",""],"attributes":{}}'

成功した場合は標準出力はないが、コンソールから”Clients”→"Resources"より確認ができる。

コンソール上での見え方

以下、補足です。

補足


クライアントのIDはget clientsのidという値から確認が可能です。

$ ./kcadm.sh get clients | jq .
...
{
    "id": "xx-xx-xx-xx-xx",
...

尚、作成したリソースは同じくAdminAPI経由でも確認が可能です。

# curl --location --request GET 'http://localhost:8080/admin/realms/master/clients/XX/authz/resource-server/resource' --header 'Content-Type: application/json' --header "Authorization: Bearer $AT" | jq .
...
  {
    "name": "test_resource",
    "owner": {
      "id": "...",
      "name": "testclient"
    },
    "ownerManagedAccess": false,
    "displayName": "testr",
    "attributes": {},
    "_id": "xx",
    "uris": [
      "/test"
    ],
    "icon_uri": ""
  }
]

以上、ご参考になれば幸いです。