【问题标题】:How to delete Keycloak realm via REST API如何通过 REST API 删除 Keycloak 领域
【发布时间】:2020-06-21 09:39:24
【问题描述】:

我无法通过 Keycloak 8.0.2 上的 REST API 删除领域。

我的 Keycloak 在 localhost:38080 上运行。我遵循了此文档https://www.keycloak.org/docs-api/8.0/rest-api/index.html#_realms_admin_resource,请参阅“删除领域”段落。首先,我在http://localhost:38080/auth/realms/master/protocol/openid-connect/token 获得了管理员用户的令牌

curl --location --request POST 'localhost:38080/auth/realms/master/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=admin' \
--data-urlencode 'password=admin' \
--data-urlencode 'client_id=vga_tests' \
--data-urlencode 'grant_type=password'

然后我使用令牌并尝试通过此调用删除example 领域

curl --location --request DELETE 'localhost:38080/auth/Example' \
--header 'Authorization: Bearer <TOKEN HERE>' \
--header 'Content-Type: application/json' \
--data-raw ''

(注意:curl 命令是导出的 Postman 调用)

我收到了这个 404 响应

{
    "error": "RESTEASY003210: Could not find resource for full path: http://localhost:38080/auth/Example"
}

我做错了什么?

【问题讨论】:

    标签: keycloak keycloak-rest-api


    【解决方案1】:

    文档不正确,我需要发送 DELETE 请求的地址是localhost:38080/auth/admin/realms/example

    卷曲命令:

    curl --location --request DELETE 'localhost:38080/auth/admin/realms/example' \
    --header 'Authorization: Bearer <TOKEN HERE>' \
    --header 'Content-Type: application/x-www-form-urlencoded'
    

    【讨论】:

      【解决方案2】:

      或者,使用CLI interface(搜索“删除领域”), 你可以这样做:

      $ kcadm.sh delete realms/example
      

      【讨论】:

        猜你喜欢
        • 2020-10-16
        • 1970-01-01
        • 2018-07-30
        • 2019-01-05
        • 2020-04-30
        • 1970-01-01
        • 2022-06-11
        • 2021-05-29
        • 1970-01-01
        相关资源
        最近更新 更多