Skip to content

Commit d66e5b8

Browse files
committed
Initial work for API documentation.
The sphinx config stuff should be basically done at this point. All the actual docstrings for the API need some extra love, I'll try to get those updated and up to snuff soon.
1 parent 370d6b8 commit d66e5b8

File tree

5 files changed

+105
-47
lines changed

5 files changed

+105
-47
lines changed

docs/api.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
API Documentation
2+
=================
3+
.. currentmodule:: flask_jwt_extended
4+
5+
.. module:: flask_jwt_extended
6+
7+
.. autoclass:: JWTManager
8+
9+
.. automethod:: __init__
10+
.. automethod:: init_app
11+
.. automethod:: user_claims_loader
12+
.. automethod:: user_identity_loader
13+
.. automethod:: expired_token_loader
14+
.. automethod:: invalid_token_loader
15+
.. automethod:: unauthorized_loader
16+
.. automethod:: needs_fresh_token_loader
17+
.. automethod:: revoked_token_loader
18+
.. automethod:: user_loader_callback_loader
19+
.. automethod:: user_loader_error_loader
20+
.. automethod:: token_in_blacklist_loader
21+
.. automethod:: claims_verification_loader
22+
.. automethod:: claims_verification_failed_loader
23+
24+
25+
Protected endpiont decorators
26+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27+
.. autofunction:: jwt_required
28+
.. autofunction:: jwt_refresh_token_required
29+
.. autofunction:: fresh_jwt_required
30+
.. autofunction:: jwt_optional
31+
32+
33+
Utilities
34+
~~~~~~~~~
35+
.. autofunction:: create_access_token
36+
.. autofunction:: create_refresh_token
37+
38+
.. attribute:: current_user
39+
40+
A LocalProxy for accessing the current user. Roughly equilivant to `get_current_user()`
41+
42+
.. autofunction:: decode_token
43+
.. autofunction:: get_current_user
44+
.. autofunction:: get_jti
45+
.. autofunction:: get_jwt_claims
46+
.. autofunction:: get_jwt_identity
47+
.. autofunction:: get_raw_jwt
48+
.. autofunction:: set_access_cookies
49+
.. autofunction:: set_refresh_cookies
50+
.. autofunction:: unset_jwt_cookies

docs/conf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121

2222
sys.path.insert(0, os.path.abspath('../../..'))
23+
sys.path.insert(0, os.path.abspath('..'))
2324
sys.path.insert(0, os.path.abspath('../flask_jwt_extended/'))
2425
sys.path.append(os.path.join(os.path.dirname(__file__), '_themes'))
2526

@@ -57,17 +58,16 @@
5758

5859
# General information about the project.
5960
project = u'flask-jwt-extended'
60-
copyright = u'2016, Landon Gilbert-Bland, rlam3'
61-
author = u'Landon Gilbert-Bland, rlam3'
61+
author = u'Landon Gilbert-Bland'
6262

6363
# The version info for the project you're documenting, acts as replacement for
6464
# |version| and |release|, also used in various other places throughout the
6565
# built documents.
6666
#
6767
# The short X.Y version.
68-
version = u'0.0.2'
68+
version = u'3.2.0'
6969
# The full version, including alpha/beta/rc tags.
70-
release = u'0.0.2'
70+
release = u'3.2.0'
7171

7272
# The language for content autogenerated by Sphinx. Refer to documentation
7373
# for a list of supported languages.
@@ -162,7 +162,7 @@
162162
# Add any paths that contain custom static files (such as style sheets) here,
163163
# relative to this directory. They are copied after the builtin static files,
164164
# so a file named "default.css" will overwrite the builtin "default.css".
165-
html_static_path = ['_static']
165+
#html_static_path = ['_static']
166166

167167
# Add any extra paths that contain custom files (such as robots.txt or
168168
# .htaccess) here, relative to this directory. These files are copied

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
Flask JWT Extended's documentation
77
==================================
88

9-
In here you will find examples of how to use Flask JWT Extended. Full API
10-
documentation is coming soon!
9+
In here you will find examples of how to use Flask JWT Extended.
1110

1211
.. toctree::
1312
:maxdepth: 2
@@ -23,3 +22,4 @@ documentation is coming soon!
2322
options
2423
blacklist_and_token_revoking
2524
tokens_in_cookies
25+
api

flask_jwt_extended/jwt_manager.py

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323

2424

2525
class JWTManager(object):
26+
"""
27+
This object is used to hold the JWT settings and callback functions.
28+
Instances :class:`JWTManager` are *not* bound to specific apps, so
29+
you can create one in the main body of your code and then bind it
30+
to your app in a factory function.
31+
"""
32+
2633
def __init__(self, app=None):
2734
"""
2835
Create the JWTManager instance. You can either pass a flask application
@@ -330,23 +337,7 @@ def claims_verification_failed_loader(self, callback):
330337
self._claims_verification_failed_callback = callback
331338
return callback
332339

333-
def create_refresh_token(self, identity, expires_delta=None):
334-
"""
335-
Creates a new refresh token
336-
337-
:param identity: The identity of this token. This can be any data that is
338-
json serializable. It can also be an object, in which case
339-
you can use the user_identity_loader to define a function
340-
that will be called to pull a json serializable identity
341-
out of this object. This is useful so you don't need to
342-
query disk twice, once for initially finding the identity
343-
in your login endpoint, and once for setting addition data
344-
in the JWT via the user_claims_loader
345-
:param expires_delta: A datetime.timedelta for how long this token should
346-
last before it expires. If this is None, it will
347-
use the 'JWT_REFRESH_TOKEN_EXPIRES` config value
348-
:return: A new refresh token
349-
"""
340+
def _create_refresh_token(self, identity, expires_delta=None):
350341
if expires_delta is None:
351342
expires_delta = config.refresh_expires
352343

@@ -360,25 +351,7 @@ def create_refresh_token(self, identity, expires_delta=None):
360351
)
361352
return refresh_token
362353

363-
def create_access_token(self, identity, fresh=False, expires_delta=None):
364-
"""
365-
Creates a new access token
366-
367-
:param identity: The identity of this token. This can be any data that is
368-
json serializable. It can also be an object, in which case
369-
you can use the user_identity_loader to define a function
370-
that will be called to pull a json serializable identity
371-
out of this object. This is useful so you don't need to
372-
query disk twice, once for initially finding the identity
373-
in your login endpoint, and once for setting addition data
374-
in the JWT via the user_claims_loader
375-
:param fresh: If this token should be marked as fresh, and can thus access
376-
fresh_jwt_required protected endpoints. Defaults to False
377-
:param expires_delta: A datetime.timedelta for how long this token should
378-
last before it expires. If this is None, it will
379-
use the 'JWT_ACCESS_TOKEN_EXPIRES` config value
380-
:return: A new access token
381-
"""
354+
def _create_access_token(self, identity, fresh=False, expires_delta=None):
382355
if expires_delta is None:
383356
expires_delta = config.access_expires
384357

flask_jwt_extended/utils.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,49 @@ def _get_jwt_manager():
7676
"application before using this method")
7777

7878

79-
def create_access_token(*args, **kwargs):
79+
def create_access_token(identity, fresh=False, expires_delta=None):
80+
"""
81+
Creates a new access token
82+
83+
:param identity: The identity of this token. This can be any data that is
84+
json serializable. It can also be an object, in which case
85+
you can use the user_identity_loader to define a function
86+
that will be called to pull a json serializable identity
87+
out of this object. This is useful so you don't need to
88+
query disk twice, once for initially finding the identity
89+
in your login endpoint, and once for setting addition data
90+
in the JWT via the user_claims_loader
91+
:param fresh: If this token should be marked as fresh, and can thus access
92+
fresh_jwt_required protected endpoints. Defaults to False
93+
:param expires_delta: A datetime.timedelta for how long this token should
94+
last before it expires. If this is None, it will
95+
use the 'JWT_ACCESS_TOKEN_EXPIRES` config value
96+
:return: A new access token
97+
"""
98+
8099
jwt_manager = _get_jwt_manager()
81-
return jwt_manager.create_access_token(*args, **kwargs)
100+
return jwt_manager._create_access_token(identity, fresh, expires_delta)
82101

83102

84-
def create_refresh_token(*args, **kwargs):
103+
def create_refresh_token(identity, expires_delta=None):
104+
"""
105+
Creates a new refresh token
106+
107+
:param identity: The identity of this token. This can be any data that is
108+
json serializable. It can also be an object, in which case
109+
you can use the user_identity_loader to define a function
110+
that will be called to pull a json serializable identity
111+
out of this object. This is useful so you don't need to
112+
query disk twice, once for initially finding the identity
113+
in your login endpoint, and once for setting addition data
114+
in the JWT via the user_claims_loader
115+
:param expires_delta: A datetime.timedelta for how long this token should
116+
last before it expires. If this is None, it will
117+
use the 'JWT_REFRESH_TOKEN_EXPIRES` config value
118+
:return: A new refresh token
119+
"""
85120
jwt_manager = _get_jwt_manager()
86-
return jwt_manager.create_refresh_token(*args, **kwargs)
121+
return jwt_manager._create_refresh_token(identity, expires_delta)
87122

88123

89124
def has_user_loader():

0 commit comments

Comments
 (0)