简体   繁体   中英

set MFA options for user using keystoneclient module

I am trying to enable default MFA for Openstack user using Python keystoneclient API keystoneclient.users.update

I have sample API curl command from Openstack documentation, where you update the "options" attribute of user account with JSON object

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

}

when I am trying to update the same in Python code I am getting below error

keystoneauth1.exceptions.http.BadRequest: Invalid input for field 'options': u'{ "multi_factor_auth_enabled": true, "multi_factor_auth_rules": [["password", "totp"]]}' is not of type 'object'

Failed validating 'type' in schema['properties']['options']:

my code is like this

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

Never mind I figured it out. MFA_dict was string, so I had to just remove single quotes and make the object dictionary.

and make lower case true into uppercase True to make it boolean

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM