{ "info": { "author": "Cromlech Team", "author_email": "", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: Zope Public License", "Programming Language :: Python" ], "description": "cromlech.jwt\n************\n\nJSON WebTokens utilities for web applications.\nCan produce and verify signed and encrypted tokens, with or without\nstorage or self-deprecation.\n\nPrerequisite\n============\n\nIn order to use the cryptographic capabilities, we create a cryptographic key.\nThis key needs to be stored in order to be reused in your app. Make sure it's\nstored in a safe place as tokens rely on this to be considered \"secure\".\n\n >>> from cromlech.jwt.components import JWTHandler\n >>> key = JWTHandler.generate_key()\n\nRead more here : http://jwcrypto.readthedocs.io.\nKey generation options available : key type, size.\n\nYou can load a key from the key value and the type :\n\n >>> key_string = JWTHandler.dump_key(key)\n >>> key = JWTHandler.load_key(key_string)\n\n\nHandler\n=======\n\nThe handler class is the carrier of the first layer of utilities.\nA handler instance can be configured to generate self-deprecating tokens.\n\nBy default, tokens have no expiration. Tokens with no expiration date can be\nstored and managed in your own application layer, implementing your own\ntimeout mechanism and policy.\n\n >>> handler = JWTHandler()\n >>> data = {\"user\": \"Cromlech User\"}\n >>> payload = handler.create_payload(**data)\n >>> sorted(payload.items()) # doctest: +ALLOW_UNICODE\n [('uid', '...'), ('user', 'Cromlech User')]\n\n\nConfiguring the timeout triggers the creation of an expiration time.\nThe timeout is an integer representing the lifespan in minutes.\n\n >>> handler = JWTHandler(auto_timeout=60)\n >>> payload = handler.create_payload(**data)\n >>> sorted(payload.items()) # doctest: +ALLOW_UNICODE\n [('exp', ...), ('uid', '...'), ('user', 'Cromlech User')]\n\nNote that an UID attribute is created by default. The base policy is to create\nan UID based on UUID (uuid4 here). You can override that method easily in a\nsubclass.\n\n\nService\n=======\n\nThe service class provides a wrapper around a handler to ease the common\noperations. It allows you to configure a handler, generate and authenticate.\nFurthermore, it has a skeleton structure to store and refresh, if you wish\nto create your own token policy.\n\n >>> from cromlech.jwt.components import JWTService\n >>> service = JWTService(key, JWTHandler)\n >>> service.handler.auto_timeout\n 60\n\n >>> import six\n >>> token = service.generate(data)\n >>> assert isinstance(token, six.string_types)\n\n >>> import json\n >>> token_data = handler.decrypt_and_verify(key, token)\n >>> sorted(json.loads(token_data).items()) # doctest: +ALLOW_UNICODE\n [('exp', ...), ('uid', '...'), ('user', 'Cromlech User')]\n\n >>> auth_data = service.check_token(token)\n >>> sorted(auth_data.items()) # doctest: +ALLOW_UNICODE\n [('exp', ...), ('uid', '...'), ('user', 'Cromlech User')]\n\n >>> import pytest\n >>> from cromlech.jwt.components import InvalidToken\n >>> with pytest.raises(InvalidToken) as invalid:\n ... service.check_token(token + 'some_altering_data')\n\n\nWe can override the payload auto-generated data, to gain flexibility:\n\n >>> data = {\"user\": \"Cromlech User\", \"uid\": \"My Own ID\"}\n >>> token = service.generate(data)\n >>> token_data = handler.decrypt_and_verify(key, token)\n >>> sorted(json.loads(token_data).items()) # doctest: +ALLOW_UNICODE\n [('exp', ...), ('uid', 'My Own ID'), ('user', 'Cromlech User')]\n\n\nThis way, we create an intentionally deprecated token to test:\n\n >>> from cromlech.jwt.utils import get_posix_timestamp, expiration_date\n >>> deprecated = get_posix_timestamp(expiration_date(-60))\n >>> data = {\"user\": \"Cromlech User\", \"exp\": deprecated}\n >>> token = service.generate(data)\n\n >>> from cromlech.jwt.components import ExpiredToken\n >>> with pytest.raises(ExpiredToken):\n ... token_data = handler.decrypt_and_verify(key, token)\n\nNote that, if your handler is not configured for self-deprecation, adding\nan expiration date on your payload will generate an error:\n\n >>> service = JWTService(key, JWTHandler, auto_deprecate=False)\n >>> deprecated = get_posix_timestamp(expiration_date(60))\n >>> data = {\"user\": \"Cromlech User\", \"exp\": deprecated}\n >>> from cromlech.jwt.components import InvalidPayload\n >>> with pytest.raises(InvalidPayload) as payload_error:\n ... token = service.generate(data)\n\n >>> payload_error.value\n InvalidPayload('Expiration is not allowed.',)\n\nCHANGES\n=======\n\n0.1 (2018-08-27)\n----------------\n\n * Initial release\n\n", "description_content_type": "", "docs_url": null, "download_url": "http://pypi.python.org/pypi/cromlech.jwt", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://gitweb.dolmen-project.org", "keywords": "", "license": "ZPL", "maintainer": "", "maintainer_email": "", "name": "cromlech.jwt", "package_url": "https://pypi.org/project/cromlech.jwt/", "platform": "", "project_url": "https://pypi.org/project/cromlech.jwt/", "project_urls": { "Download": "http://pypi.python.org/pypi/cromlech.jwt", "Homepage": "http://gitweb.dolmen-project.org" }, "release_url": "https://pypi.org/project/cromlech.jwt/0.1/", "requires_dist": null, "requires_python": "", "summary": "JWT support for Cromlech", "version": "0.1" }, "last_serial": 4211007, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "6860ea6b2a30090b0c86e744f627053e", "sha256": "ec521ffd4adbe3feda0e0e8fbd5d70476ed7ce0ef1849af6eeb1a0a8ec0de5f3" }, "downloads": -1, "filename": "cromlech.jwt-0.1.tar.gz", "has_sig": false, "md5_digest": "6860ea6b2a30090b0c86e744f627053e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6330, "upload_time": "2018-08-27T13:12:40", "url": "https://files.pythonhosted.org/packages/f6/fd/4cbe078e78cd999690c48566f28325b0fea1ac8f7f5a7bb58772ddda79ef/cromlech.jwt-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6860ea6b2a30090b0c86e744f627053e", "sha256": "ec521ffd4adbe3feda0e0e8fbd5d70476ed7ce0ef1849af6eeb1a0a8ec0de5f3" }, "downloads": -1, "filename": "cromlech.jwt-0.1.tar.gz", "has_sig": false, "md5_digest": "6860ea6b2a30090b0c86e744f627053e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6330, "upload_time": "2018-08-27T13:12:40", "url": "https://files.pythonhosted.org/packages/f6/fd/4cbe078e78cd999690c48566f28325b0fea1ac8f7f5a7bb58772ddda79ef/cromlech.jwt-0.1.tar.gz" } ] }