Skip to content

Commit 45d98b2

Browse files
committed
Moving documentation from github to readthedocs
1 parent 4e8509a commit 45d98b2

File tree

6 files changed

+111
-7
lines changed

6 files changed

+111
-7
lines changed

docs/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
SPHINXOPTS =
66
SPHINXBUILD = sphinx-build
77
PAPER =
8-
BUILDDIR = build
8+
BUILDDIR = _build
99

1010
# Internal variables.
1111
PAPEROPT_a4 = -D latex_paper_size=a4
1212
PAPEROPT_letter = -D latex_paper_size=letter
13-
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
13+
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
1414
# the i18n builder cannot share the environment and doctrees with the others
15-
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
15+
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
1616

1717
.PHONY: help
1818
help:

docs/basic_usage.rst

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Basic Usage
2+
===========
3+
4+
5+
In its simplest form, there is not much to using flask_jwt_extended.
6+
7+
8+
.. code-block :: python
9+
10+
from flask import Flask, jsonify, request
11+
from flask_jwt_extended import JWTManager, jwt_required, create_access_token
12+
13+
app = Flask(__name__)
14+
app.secret_key = 'super-secret' # Change this!
15+
16+
# Setup the Flask-JWT-Extended extension
17+
jwt = JWTManager(app)
18+
19+
20+
# Provide a method to create access tokens. The create_access_token() function
21+
# is used to actually generate the token
22+
@app.route('/login', methods=['POST'])
23+
def login():
24+
username = request.json.get('username', None)
25+
password = request.json.get('password', None)
26+
if username != 'test' and password != 'test':
27+
return jsonify({"msg": "Bad username or password"}), 401
28+
29+
ret = {'access_token': create_access_token(username)}
30+
return jsonify(ret), 200
31+
32+
33+
# Protect a view with jwt_required, which requires a valid access token in the
34+
# request to access.
35+
@app.route('/protected', methods=['GET'])
36+
@jwt_required
37+
def protected():
38+
return jsonify({'hello': 'world'}), 200
39+
40+
if __name__ == '__main__':
41+
app.run()
42+
43+
44+
To access a jwt_required protected view, all we have to do is send an authorization head with the request that include the token. The header looks like this:
45+
46+
47+
.. code-block :: bash
48+
49+
Authorization: Bearer <access_token>
50+
51+
52+
We can see this in action using CURL:
53+
54+
.. code-block :: bash
55+
56+
$ curl --write-out "%{http_code}\n" http://localhost:5000/protected
57+
{
58+
"msg": "Missing Authorization Header"
59+
}
60+
401
61+
62+
$ curl --write-out "%{http_code}\n" -H "Content-Type: application/json" -X POST -d '{"username":"test","password":"test"}' http://localhost:5000/login
63+
{
64+
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6dHJ1ZSwianRpIjoiZjhmNDlmMjUtNTQ4OS00NmRjLTkyOWUtZTU2Y2QxOGZhNzRlIiwidXNlcl9jbGFpbXMiOnt9LCJuYmYiOjE0NzQ0NzQ3OTEsImlhdCI6MTQ3NDQ3NDc5MSwiaWRlbnRpdHkiOiJ0ZXN0IiwiZXhwIjoxNDc0NDc1NjkxLCJ0eXBlIjoiYWNjZXNzIn0.vCy0Sec61i9prcGIRRCbG8e9NV6_wFH2ICFgUGCLKpc"
65+
}
66+
200
67+
68+
$ export ACCESS="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6dHJ1ZSwianRpIjoiZjhmNDlmMjUtNTQ4OS00NmRjLTkyOWUtZTU2Y2QxOGZhNzRlIiwidXNlcl9jbGFpbXMiOnt9LCJuYmYiOjE0NzQ0NzQ3OTEsImlhdCI6MTQ3NDQ3NDc5MSwiaWRlbnRpdHkiOiJ0ZXN0IiwiZXhwIjoxNDc0NDc1NjkxLCJ0eXBlIjoiYWNjZXNzIn0.vCy0Sec61i9prcGIRRCbG8e9NV6_wFH2ICFgUGCLKpc"
69+
70+
$ curl --write-out "%{http_code}\n" -H "Authorization: Bearer $ACCESS" http://localhost:5000/protected
71+
{
72+
"hello": "world"
73+
}
74+
200
File renamed without changes.
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
.. flask-jwt-extended documentation master file, created by
2-
sphinx-quickstart on Thu Oct 6 13:07:36 2016.
2+
sphinx-quickstart on Fri Oct 7 10:31:53 2016.
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
66
Welcome to flask-jwt-extended's documentation!
77
==============================================
88

9-
Contents:
10-
119
.. toctree::
1210
:maxdepth: 2
1311

12+
installation
13+
basic_usage
14+
15+
add_custom_data_claims
16+
refresh_tokens
17+
token_freshness
18+
changing_default_behavior
19+
options
20+
blacklist_and_token_revoking
21+
testing_and_code_coverage
22+
23+
1424

1525

1626
Indices and tables
@@ -19,4 +29,3 @@ Indices and tables
1929
* :ref:`genindex`
2030
* :ref:`modindex`
2131
* :ref:`search`
22-

docs/installation.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Installation
2+
==============
3+
4+
5+
6+
The easiest way to start working with this extension with pip:
7+
8+
.. code-block:: bash
9+
10+
$ pip install flask-jwt-extended
11+
12+
If you prefer to install from source, you can clone this repo and run
13+
14+
.. code-block:: bash
15+
16+
$ python setup.py install

docs/watchdocumentation.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
watchmedo shell-command \
2+
--patterns="*.rst" \
3+
--ignore-pattern='_build/*' \
4+
--recursive \
5+
--command='make html'

0 commit comments

Comments
 (0)