{ "info": { "author": "deginner", "author_email": "support@deginner.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Topic :: Software Development :: Libraries" ], "description": "flask-bitjws |PyPi version| |Build Status| |Coverage| |Gitter|\n==============================================================\n\nFlask extension for `bitjws `__\nauthentication.\n\nInstall\n-------\n\nBy default it's expected that\n`secp256k1 `__ is available, so\ninstall it before proceeding; make sure to run\n``./configure --enable-module-recovery``. If you're using some other\nlibrary that provides the functionality necessary for this, check the\n**Using a custom library** section of the bitjws README.\n\nFlask-bitjws can be installed by running:\n\n``pip install flask-bitjws``\n\nBuilding secp256k1\n''''''''''''''''''\n\nIn case you need to install the ``secp256k1`` C library, the following\nsequence of commands is recommended. If you already have ``secp256k1``,\nmake sure it was compiled from the expected git commit or it might fail\nto work due to API incompatibilities.\n\n::\n\n git clone git://github.com/bitcoin/secp256k1.git libsecp256k1\n cd libsecp256k1\n git checkout d7eb1ae96dfe9d497a26b3e7ff8b6f58e61e400a\n ./autogen.sh\n ./configure --enable-module-recovery\n make\n sudo make install\n\nInitialization\n--------------\n\nInitialize a flask\\_bitjws Application\n''''''''''''''''''''''''''''''''''''''\n\nThe flask-bitjws package provides a Flask Application wrapper. To enable\nbitjws authentication, initialize FlaskBitjws with your flask app as the\nfirst argument.\n\n.. code:: Python\n\n from flask import Flask\n from flask_bitjws import FlaskBitjws\n\n app = Flask(__name__)\n FlaskBitjws(app)\n\nCustomizing LoginManager\n''''''''''''''''''''''''\n\n| Flask-bitjws uses\n`flask-login `__ to manage\nuser login and authentication. By default,\n| the FlaskBitjws initialization will create a new LoginManager for you.\nIf you need to customize, you can alternately provide your own. Just be\naware that it's request\\_loader needs to be left as is.\n\n.. code:: Python\n\n from flask import Flask\n from flask_bitjws import FlaskBitjws\n from flask.ext.login import LoginManager\n\n # Your LoginManager\n lm = LoginManager()\n\n app = Flask(__name__)\n FlaskBitjws(app, loginmanager=lm)\n\nInitialize with private key\n'''''''''''''''''''''''''''\n\nTo provide a private key for your server to use in signing, include a\nprivkey argument to Application.\\ **init**\\ ().\n\n.. code:: Python\n\n from flask import Flask\n from flask_bitjws import FlaskBitjws\n\n # Your bitjws private key in WIF\n privkey = \"KweY4PozGhtkGPMvvD7vk7nLiN6211XZ2QGxLBMginAQW7MBbgp8\"\n\n app = Flask(__name__)\n FlaskBitjws(app, privkey=privkey)\n\nUsage\n-----\n\nRequests\n''''''''\n\nFor all routes that require login (i.e. wrapped in @login\\_required),\nthe FlaskBitjws login manager will validate the bitjws headers and data,\nand match it up to a user.\n\nIf authentication is successful, the request will have two new\nattributes \"jws\\_payload\", and \"jws\\_header\".\n\nIf authentication fails, flask-login will return a 401 error.\n\n::\n\n from flask import Flask\n from flask_bitjws import FlaskBitjws\n\n # Your bitjws private key in WIF\n privkey = \"KweY4PozGhtkGPMvvD7vk7nLiN6211XZ2QGxLBMginAQW7MBbgp8\"\n\n app = Flask(__name__)\n FlaskBitjws(app, privkey=privkey)\n\n @app.route('/user', methods=['POST'])\n @login_required\n def post_user():\n # request.jws_payload should exist and have the deserialized JWT claimset\n username = request.jws_payload.get('username')\n # request.jws_header should exist and have the sender's public key\n address = request.jws_header['kid']\n user = {'username': username, 'address': address}\n # return a bitjws signed and formatted response\n return current_app.create_bitjws_response(user)\n\nResponses\n'''''''''\n\nWhen you're ready to respond, use the create\\_bitjws\\_response method to\nconstruct your response in bitjws format.\n\n::\n\n response_object = {'can be': 'a dict', 'or any': 'valid json'}\n return current_app.create_bitjws_response(response_object)\n\nYour Database\n-------------\n\nFlask-bitjws comes with an example, in-memory data store for users and\nnonces. Using this example \"database\" is extremely insecure and\nunstable. It is recommended to provide bindings to your own persistent\ndatabase for production use. This can be done by passing\n``FlaskBitjws.__init__`` two functions: get\\_last\\_nonce, and\nget\\_user\\_by\\_key. These should do pretty much what their names say.\n\nSQLAlchemy Example\n''''''''''''''''''\n\n::\n\n def get_last_nonce(app, key, nonce):\n \"\"\"\n This method is only an example! Replace it with a real nonce database.\n\n :param str key: the public key the nonce belongs to\n :param int nonce: the latest nonce\n \"\"\"\n uk = ses.query(UserKey).filter(UserKey.key==key)\\\n .filter(UserKey.last_nonce