首页 > 解决方案 > 使用 keystoneclient 模块为用户设置 MFA 选项

问题描述

我正在尝试使用 Python keystoneclient API keystoneclient.users.update为 Openstack 用户启用默认 MFA

我有来自 Openstack 文档的示例 API curl 命令,您可以在其中使用 JSON 对象更新用户帐户的“选项”属性

{
"user": {
    "options": {
        "multi_factor_auth_enabled": true,
        "multi_factor_auth_rules": [
            ["password", "totp"]
        ]
    }
}

}

当我尝试在 Python 代码中更新相同的内容时,出现以下错误

keystoneauth1.exceptions.http.BadRequest:字段'options'的输入无效:u'{“multi_factor_auth_enabled”:true,“multi_factor_auth_rules”:[[“password”,“totp”]]}'不是'object'类型

在架构 ['properties']['options'] 中验证 'type' 失败:

我的代码是这样的

MFA_dict = '{ "multi_factor_auth_enabled": true, "multi_factor_auth_rules": [["password", "totp"]]}'
    user = keystone.users.update(user_id, options=MFA_dict)

标签: openstackmulti-factor-authenticationopenstack-keystone

解决方案


没关系,我想通了。MFA_dict 是字符串,所以我只需要删除单引号并制作对象字典。

并将小写 true 变为大写True以使其成为布尔值

MFA_dict = { "multi_factor_auth_enabled": True, "multi_factor_auth_rules": [["password", "totp"]]}

推荐阅读