def encode(secret: Union[str, bytes], payload: dict = None,<EOL>alg: str = default_alg, header: dict = None) -> str:
secret = util.to_bytes(secret)<EOL>payload = payload or {}<EOL>header = header or {}<EOL>header_json = util.to_bytes(json.dumps(header))<EOL>header_b64 = util.b64_encode(header_json)<EOL>payload_json = util.to_bytes(json.dumps(payload))<EOL>payload_b64 = util.b64_encode(payload_json)<EOL>pre_signature = util.join(header_b64, payload_b64)<EOL>signature = _hash(secret, pre_signature, alg)<EOL>signature_b64 = util.b64_encode(signature)<EOL>token = util.join(pre_signature, signature_b64)<EOL>return util.from_bytes(token)<EOL>
:param secret: The secret used to encode the token.
:type secret: Union[str, bytes]
:param payload: The payload to be encoded in the token.
:type payload: dict
:param alg: The algorithm used to hash the token.
:type alg: str
:param header: The header to be encoded in the token.
:type header: dict
:return: A new token
:rtype: str