#!/usr/bin/python

DOCUMENTATION = '''
---
module: smardigo_user_token
short_description: create smardigo user token
'''
EXAMPLES = '''
- hosts: localhost
  tasks:
  - name: create smardigo user token
    smardigo_user_token:
      secret: ""
      user_id: ""
    register: result
  - debug: var=result
'''

from jose import jwe
from ansible.module_utils.basic import *

def main():

    fields = {
        "secret": {"default": False, "type": "str"},
        "user_id": {"default": False, "type": "str"}
    }

    module = AnsibleModule(argument_spec=fields)

    token = jwe.encrypt('{"sub":"' +  module.params["user_id"] + '"}', module.params["secret"], algorithm='dir', encryption='A128CBC-HS256')

    module.exit_json(changed=True, token=token)

if __name__ == '__main__':
    main()
