fix(matrix_token_login): improve handling of the admin flag

This fixes the data type of the admin flag, which was previously a
string. Now it's a bool. Additionally, if the admin flag is omitted,
it's now also ommitted in the JWT sent to the server, so that existing
admin status isn't revoked by a call which doesn't include it.
This commit is contained in:
Jan Christian Grünhage 2022-05-05 10:46:40 +02:00
parent 12ca4d992a
commit 063db8954a
No known key found for this signature in database
GPG key ID: EEC1170CE56FA2ED

View file

@ -74,7 +74,7 @@ from ansible_collections.famedly.matrix.plugins.module_utils.matrix import *
async def run_module():
module_args = dict(
key=dict(type='str', required=True),
admin=dict(type='str', required=False),
admin=dict(type='bool', required=False),
)
result = dict(
@ -99,8 +99,6 @@ async def run_module():
await module.fail_json(msg="A key has to be provided")
admin = module.params['admin']
if admin is None:
admin = false
method, path, data = Api.login(
client.user,
@ -116,9 +114,12 @@ async def run_module():
claims = {
"iss": "Matrix UIA Login Ansible Module",
"sub": client.user,
"admin": admin,
"exp": int(time.time()) + 60 * 30,
}
if admin is not None:
claims["admin"] = admin
token = jwt.JWT(header={"alg": "HS512"},
claims=claims)