{ "info": { "author": "Globo.com", "author_email": "timecore@corp.globo.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3" ], "description": "alf-auth0 \n===\n\n.. image:: https://travis-ci.org/globocom/alf.svg?branch=master\n :target: https://travis-ci.org/globocom/alf\n\nPython OAuth 2 Client\n---------------------\n\n`alf` is an OAuth 2 Client based on `requests.Session\n`_\nwith seamless support for the `Client Credentials Flow\n`_.\n\n.. image:: /assets/alf.jpeg?raw=true\n\nFeatures\n--------\n\n* Automatic token retrieving and renewing\n* Token expiration control\n* Automatic token storage\n* Automatic retry on status 401 (UNAUTHORIZED)\n* Works with Auth0 Client Credentials Flow\n\nUsage\n-----\n\nInitialize the client and use it as a `requests.Session\n`_\nobject.\n\n.. code-block:: python\n\n from alf.client import Client\n\n alf = Client(\n token_endpoint='http://example.com/token',\n client_id='client-id',\n client_secret='secret')\n\n resource_uri = 'http://example.com/resource'\n\n alf.put(\n resource_uri, data='{\"name\": \"alf\"}',\n headers={'Content-Type': 'application/json'})\n\n alf.get(resource_uri)\n\n alf.delete(resource_uri)\n\nUsing your custom token storage\n-------------------------------\n\nNow passing an object with get and set attributes you can store or retrieve a token.\n\nThis object can be a Redis, Memcache or your custom object.\n\n.. code-block:: python\n\n from alf.client import Client\n from redis import StrictRedis\n\n redis = StrictRedis(host='localhost', port=6379, db=0)\n\n alf = Client(\n token_endpoint='http://example.com/token',\n client_id='client-id',\n client_secret='secret',\n token_storage=redis)\n\n resource_uri = 'http://example.com/resource'\n\n alf.put(\n resource_uri, data='{\"name\": \"alf\"}',\n headers={'Content-Type': 'application/json'})\n\n alf.get(resource_uri)\n\n alf.delete(resource_uri)\n\n\nUsing alf with Auth0\n-------------------------------\n\nFor the Client to work with Auth0 you need to initialize it with\n``audience`` and ``token_default_expire_in``. \n\nAuth0 is not returning ``expires_in`` when you call authentication endpoint. As a result you should\nset ``token_default_expire_in`` as the same value (or a bit smaller, to be safe) that you \nhave set it in Auth0 management console > APIs > > Settings > \nToken Expiration (Seconds) field \n\n``Audience`` should be set as your API Identifier in Auth0.\n\n.. code-block:: python\n\n from alf.client import Client\n\n alf = Client(\n token_endpoint='http://example.com/token',\n audience='http://api.example.com/my-api/',\n token_default_expire_in=86400\n client_id='client-id',\n client_secret='secret')\n\n resource_uri = 'http://example.com/resource'\n\n\nHow does it work?\n-----------------\n\nBefore the request, a token will be requested on the authentication endpoint\nand a JSON response with the ``access_token`` and ``expires_in`` keys will be\nexpected.\n\nMultiple attempts will be issued after an error response from the endpoint if\nthe ``token_retries`` argument is used. Check `token-retrying`_ for more info.\n\n``alf`` keeps the token until it is expired according to the ``expires_in``\nvalue.\n\nThe token will be used on a `Bearer authorization\nheader `_ for\nthe original request.\n\n.. code-block::\n\n GET /resource/1 HTTP/1.1\n Host: example.com\n Authorization: Bearer token-12312\n\nIf the request fails with a 401 (UNAUTHORIZED) status, a new token is retrieved\nfrom the endpoint and the request is retried. This happens only once, if it\nfails again the error response is returned.\n\nThe token will be reused for every following request until it is expired.\n\n\n.. _token-retrying:\n\nToken Retrying\n--------------\n\nThe client supports the `retry interface from urllib3 `_ to repeat attempts to\nretrieve the token from the endpoint.\n\nThe following code will retry the token request 5 times when the response status\nis 500 and it will wait 0.3 seconds longer after each error (known as\n`backoff `_).\n\n.. code-block:: python\n\n from requests.packages.urllib3.util import Retry\n from alf.client import Client\n\n alf = Client(\n token_endpoint='http://example.com/token',\n client_id='client-id',\n client_secret='secret',\n token_retry=Retry(total=5, status_forcelist=[500], backoff_factor=0.3))\n\nWorkflow\n--------\n\n.. image:: /assets/workflow.png?raw=true\n\nTroubleshooting\n---------------\n\nIn case of an error retrieving a token, the error response will be returned,\nthe real request won't happen.\n\n\nRelated projects\n----------------\n\n`djalf `_\n''''''''''''''''''''''''''''''''''''''''''''''''''\n\nAn extended client that uses Django's cache backend to share tokens between\nserver instances.\n\n\n`tornado-alf `_\n''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n\nA port of the `alf` client using tornado's `AsyncHTTPClient`.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/globocom/alf", "keywords": "oauth client client_credentials requests auth0", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "alf-auth0", "package_url": "https://pypi.org/project/alf-auth0/", "platform": "", "project_url": "https://pypi.org/project/alf-auth0/", "project_urls": { "Homepage": "https://github.com/globocom/alf" }, "release_url": "https://pypi.org/project/alf-auth0/0.8.1/", "requires_dist": [ "requests (>=1.2.3)" ], "requires_python": "", "summary": "OAuth Client adapted to work with Auth0", "version": "0.8.1" }, "last_serial": 4000139, "releases": { "0.8.1": [ { "comment_text": "", "digests": { "md5": "e1da9c852df7a962022dc8e8ae688042", "sha256": "0107c7d0e03a59560b96373af624d5965d98ddb5e87ebce0dc481e1e178da10b" }, "downloads": -1, "filename": "alf_auth0-0.8.1-py2-none-any.whl", "has_sig": false, "md5_digest": "e1da9c852df7a962022dc8e8ae688042", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 11568, "upload_time": "2018-06-25T12:38:42", "url": "https://files.pythonhosted.org/packages/f7/09/2322e080f4d6ecac713b95813ef417e91d6d3e9b6a534cb227f6da5b7cab/alf_auth0-0.8.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c28ba716b52d9802a3516f9ee3f29efe", "sha256": "c6fdd807f3789d6002e9956f72058394484cd6dd9fd80e47c5c15d4ace339a04" }, "downloads": -1, "filename": "alf-auth0-0.8.1.tar.gz", "has_sig": false, "md5_digest": "c28ba716b52d9802a3516f9ee3f29efe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8373, "upload_time": "2018-06-25T12:38:43", "url": "https://files.pythonhosted.org/packages/84/52/57451728225f480bd1de17a4d1eec2130fe3a4a1c0e9f02cc1647c17b764/alf-auth0-0.8.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e1da9c852df7a962022dc8e8ae688042", "sha256": "0107c7d0e03a59560b96373af624d5965d98ddb5e87ebce0dc481e1e178da10b" }, "downloads": -1, "filename": "alf_auth0-0.8.1-py2-none-any.whl", "has_sig": false, "md5_digest": "e1da9c852df7a962022dc8e8ae688042", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 11568, "upload_time": "2018-06-25T12:38:42", "url": "https://files.pythonhosted.org/packages/f7/09/2322e080f4d6ecac713b95813ef417e91d6d3e9b6a534cb227f6da5b7cab/alf_auth0-0.8.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c28ba716b52d9802a3516f9ee3f29efe", "sha256": "c6fdd807f3789d6002e9956f72058394484cd6dd9fd80e47c5c15d4ace339a04" }, "downloads": -1, "filename": "alf-auth0-0.8.1.tar.gz", "has_sig": false, "md5_digest": "c28ba716b52d9802a3516f9ee3f29efe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8373, "upload_time": "2018-06-25T12:38:43", "url": "https://files.pythonhosted.org/packages/84/52/57451728225f480bd1de17a4d1eec2130fe3a4a1c0e9f02cc1647c17b764/alf-auth0-0.8.1.tar.gz" } ] }