Keycloak 管理 API。不允许使用方法来放置用户个人资料

问题描述 投票:0回答:1

我正在尝试向 Keycloak Admin API Rest 执行一些请求以执行一些操作。

我需要向领域用户配置文件添加一个新属性。在文档中:Keycloak Admin REST API提供了此端点:

PUT /admin/realms/{realm}/users/profile
,其中根据简要描述,目标是设置用户配置文件的配置。在请求正文中,我包含了默认配置,以及一个新属性。

提出此要求时:

### Add phone to user profile
PUT {{baseUrl}}/admin/reamls/{{realm}}/users/profile
Authorization: Bearer {{access_token}}
Content-Type: application/json

{
    "UPConfig": {
        "attributes": [
         {
            "name": "username",
            "displayName": "${username}",
            "validations": {
                "length": {
                    "min": 3,
                    "max": 255
                },
                "username-prohibited-characters": {},
                "up-username-not-idn-homograph": {}
            },
            "permissions": {
                "view": ["admin", "user"],
                "edit": ["admin", "user"]
            },
            "multivalued": false
        },
        {
            "name": "email",
            "displayName": "${email}",
            "validations": {
                "email": {},
                "length": {
                    "max": 255
                }
            },
            "required": {
                "roles": ["user"]
            },
            "permissions": {
                "view": ["admin", "user"],
                "edit": ["admin", "user"]
            },
            "multivalued": false
        },
        {
            "name": "firstName",
            "displayName": "${firstName}",
            "validations": {
                "length": {
                    "max": 255
                },
                "person-name-prohibited-characters": {}
            },
            "required": {
                "roles": ["user"]
            },
            "permissions": {
                "view": ["admin", "user"],
                "edit": ["admin", "user"]
            },
            "multivalued": false
        },
        {
            "name": "lastName",
            "displayName": "${lastName}",
            "validations": {
                "length": {
                    "max": 255
                },
                "person-name-prohibited-characters": {}
            },
            "required": {
                "roles": ["user"]
            },
            "permissions": {
                "view": ["admin", "user"],
                "edit": ["admin", "user"]
            },
            "multivalued": false
        },
        {
            "name": "phone",
            "displayName": "User phone",
            "required": {
                "roles": ["user"]
            },
            "permissions": {
                "view": ["admin", "user"],
                "edit": ["admin", "user"]
            },
            "multivalued": false
        }],
        "groups": [
        {
            "name": "user-metadata",
            "displayHeader": "User metadata",
            "displayDescription": "Attributes, which refer to user metadata"
        }]
    }
}

我得到:

{
  "error": "HTTP 405 Method Not Allowed",
  "error_description": "For more on this error consult the server log at the debug level."
}

我可能做错了什么?

keycloak keycloak-rest-api
1个回答
0
投票

我已成功阅读用户配置文件:

from keycloak import KeycloakAdmin
from keycloak import KeycloakOpenIDConnection

url = "http://localhost:8080/"
username='admin'
password='sadmin'
client_id='admin-cli'
realm_name="master"

keycloak_connection = KeycloakOpenIDConnection(
                        server_url=url,
                        username=username,
                        password=password,
                        client_id=client_id,
                        realm_name=realm_name)

keycloak_admin = KeycloakAdmin(connection=keycloak_connection)

URL_ADMIN_USER_PROFILE = "admin/realms/{realm-name}/users/profile"
params_path = {"realm-name": keycloak_admin.get_current_realm()}
data_raw = keycloak_admin.connection.raw_get(URL_ADMIN_USER_PROFILE.format(**params_path))
user_paylaod = data_raw.json()

但是我无法将其发回:

import json
data_raw = keycloak_admin.connection.raw_post(
    URL_ADMIN_USER_PROFILE.format(**params_path),
    data=json.dumps(user_profile_payload),
)
data_raw.json()

我的回应:

{'error': 'HTTP 405 Method Not Allowed'}

如果您找到问题的解决方案,可以发布吗?

© www.soinside.com 2019 - 2024. All rights reserved.