Skip to content

Commit 60bcbab

Browse files
author
mongkok
committed
Black
1 parent c5f59fb commit 60bcbab

7 files changed

Lines changed: 90 additions & 83 deletions

File tree

docs/authentication.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Authentication
1212
def resolve_viewer(self, info, **kwargs):
1313
user = info.context.user
1414
if not user.is_authenticated:
15-
raise Exception('Authentication credentials were not provided')
15+
raise Exception("Authentication credentials were not provided")
1616
return user
1717

1818

@@ -43,11 +43,11 @@ When a token is requested and ``jwt_cookie`` decorator is set, the response will
4343
from graphql_jwt.decorators import jwt_cookie
4444

4545
urlpatterns = [
46-
path('graphql/', jwt_cookie(GraphQLView.as_view())),
46+
path("graphql/", jwt_cookie(GraphQLView.as_view())),
4747
]
4848

4949

50-
If the ``jwt_cookie`` decorator is set, consider adding `CSRF middleware <https://docs.djangoproject.com/es/2.1/ref/csrf/>`_ ``'django.middleware.csrf.CsrfViewMiddleware'`` to provide protection against `Cross Site Request Forgeries <https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)>`_.
50+
If the ``jwt_cookie`` decorator is set, consider adding `CSRF middleware <https://docs.djangoproject.com/es/2.1/ref/csrf/>`_ ``"django.middleware.csrf.CsrfViewMiddleware"`` to provide protection against `Cross Site Request Forgeries <https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)>`_.
5151

5252
A cookie-based authentication does not require sending the tokens as a mutation input argument.
5353

@@ -107,7 +107,7 @@ Enable the argument authentication in your settings:
107107
::
108108

109109
GRAPHQL_JWT = {
110-
'JWT_ALLOW_ARGUMENT': True,
110+
"JWT_ALLOW_ARGUMENT": True,
111111
}
112112

113113

docs/conf.py

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@
2424
sys.path.insert(0, str(ROOT_DIR))
2525
sys.path.insert(0, str(ROOT_DIR.parent))
2626

27-
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
27+
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings"
2828
django.setup()
2929

3030
import graphql_jwt # NOQA E402
3131

3232
# -- Project information -----------------------------------------------------
3333

34-
project = 'Django GraphQL JWT'
35-
author = 'mongkok'
34+
project = "Django GraphQL JWT"
35+
author = "mongkok"
3636

37-
copyright = '{year}, {author}'.format(
38-
year=datetime.datetime.today().year,
39-
author=author)
37+
copyright = "{year}, {author}".format(
38+
year=datetime.datetime.today().year, author=author
39+
)
4040

4141
# The short X.Y version
4242
version = graphql_jwt.__version__
@@ -54,24 +54,24 @@
5454
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
5555
# ones.
5656
extensions = [
57-
'sphinx.ext.autodoc',
58-
'sphinx.ext.coverage',
59-
'sphinx.ext.intersphinx',
60-
'sphinx.ext.todo',
61-
'sphinx.ext.viewcode',
57+
"sphinx.ext.autodoc",
58+
"sphinx.ext.coverage",
59+
"sphinx.ext.intersphinx",
60+
"sphinx.ext.todo",
61+
"sphinx.ext.viewcode",
6262
]
6363

6464
# Add any paths that contain templates here, relative to this directory.
65-
templates_path = ['_templates']
65+
templates_path = ["_templates"]
6666

6767
# The suffix(es) of source filenames.
6868
# You can specify multiple suffix as a list of string:
6969
#
7070
# source_suffix = ['.rst', '.md']
71-
source_suffix = '.rst'
71+
source_suffix = ".rst"
7272

7373
# The master toctree document.
74-
master_doc = 'index'
74+
master_doc = "index"
7575

7676
# The language for content autogenerated by Sphinx. Refer to documentation
7777
# for a list of supported languages.
@@ -83,42 +83,42 @@
8383
# List of patterns, relative to source directory, that match files and
8484
# directories to ignore when looking for source files.
8585
# This pattern also affects html_static_path and html_extra_path.
86-
exclude_patterns = ['_build', '.DS_Store']
86+
exclude_patterns = ["_build", ".DS_Store"]
8787

8888
# The name of the Pygments (syntax highlighting) style to use.
89-
pygments_style = 'sphinx'
89+
pygments_style = "sphinx"
9090

9191
# If true, `todo` and `todoList` produce output, else they produce nothing.
9292
todo_include_todos = True
9393

9494

9595
# Sphinx setup
9696
def setup(app):
97-
app.add_stylesheet('style.css')
97+
app.add_stylesheet("style.css")
9898

9999

100100
# -- Options for HTML output -------------------------------------------------
101101

102102
# The theme to use for HTML and HTML Help pages. See the documentation for
103103
# a list of builtin themes.
104104
#
105-
html_theme = 'alabaster'
105+
html_theme = "alabaster"
106106

107107
# Theme options are theme-specific and customize the look and feel of a theme
108108
# further. For a list of options available for each theme, see the
109109
# documentation.
110110
#
111111
html_theme_options = {
112-
'logo': 'logo.png',
113-
'show_powered_by': False,
114-
'fixed_sidebar': True,
115-
'github_user': 'flavors',
116-
'github_repo': 'django-graphql-jwt',
117-
'github_banner': True,
118-
'github_button': True,
119-
'github_type': 'star',
120-
'sidebar_list': '#e535ab',
121-
'description': 'JSON Web Token (JWT) authentication for Graphene Django',
112+
"logo": "logo.png",
113+
"show_powered_by": False,
114+
"fixed_sidebar": True,
115+
"github_user": "flavors",
116+
"github_repo": "django-graphql-jwt",
117+
"github_banner": True,
118+
"github_button": True,
119+
"github_type": "star",
120+
"sidebar_list": "#e535ab",
121+
"description": "JSON Web Token (JWT) authentication for Graphene Django",
122122
}
123123

124124

@@ -130,13 +130,13 @@ def setup(app):
130130
# The name of an image file (within the static path) to use as favicon of the
131131
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
132132
# pixels large.
133-
html_favicon = 'favicon.ico'
133+
html_favicon = "favicon.ico"
134134

135135

136136
# Add any paths that contain custom static files (such as style sheets) here,
137137
# relative to this directory. They are copied after the builtin static files,
138138
# so a file named "default.css" will overwrite the builtin "default.css".
139-
html_static_path = ['_static']
139+
html_static_path = ["_static"]
140140

141141
# Custom sidebar templates, must be a dictionary that maps document names
142142
# to template names.
@@ -147,11 +147,11 @@ def setup(app):
147147
# 'searchbox.html']``.
148148
#
149149
html_sidebars = {
150-
'**': [
151-
'about.html',
152-
'navigation.html',
153-
'relations.html',
154-
'searchbox.html',
150+
"**": [
151+
"about.html",
152+
"navigation.html",
153+
"relations.html",
154+
"searchbox.html",
155155
],
156156
}
157157

@@ -168,7 +168,7 @@ def setup(app):
168168
# -- Options for HTMLHelp output ---------------------------------------------
169169

170170
# Output file base name for HTML help builder.
171-
htmlhelp_basename = 'DjangoGraphQLJWTdoc'
171+
htmlhelp_basename = "DjangoGraphQLJWTdoc"
172172

173173

174174
# -- Options for LaTeX output ------------------------------------------------
@@ -177,15 +177,12 @@ def setup(app):
177177
# The paper size ('letterpaper' or 'a4paper').
178178
#
179179
# 'papersize': 'letterpaper',
180-
181180
# The font size ('10pt', '11pt' or '12pt').
182181
#
183182
# 'pointsize': '10pt',
184-
185183
# Additional stuff for the LaTeX preamble.
186184
#
187185
# 'preamble': '',
188-
189186
# Latex figure (float) alignment
190187
#
191188
# 'figure_align': 'htbp',
@@ -195,8 +192,13 @@ def setup(app):
195192
# (source start file, target name, title,
196193
# author, documentclass [howto, manual, or own class]).
197194
latex_documents = [
198-
(master_doc, 'DjangoGraphQLJWT.tex', 'Django GraphQL JWT Documentation',
199-
author, 'manual'),
195+
(
196+
master_doc,
197+
"DjangoGraphQLJWT.tex",
198+
"Django GraphQL JWT Documentation",
199+
author,
200+
"manual",
201+
),
200202
]
201203

202204

@@ -205,8 +207,7 @@ def setup(app):
205207
# One entry per manual page. List of tuples
206208
# (source start file, name, description, authors, manual section).
207209
man_pages = [
208-
(master_doc, 'django-graphql-jwt', 'Django GraphQL JWT Documentation',
209-
[author], 1),
210+
(master_doc, "django-graphql-jwt", "Django GraphQL JWT Documentation", [author], 1),
210211
]
211212

212213

@@ -216,9 +217,15 @@ def setup(app):
216217
# (source start file, target name, title, author,
217218
# dir menu entry, description, category)
218219
texinfo_documents = [
219-
(master_doc, 'Django-GraphQLJWT', 'Django GraphQL JWT Documentation',
220-
author, 'DjangoGraphQLJWT', 'One line description of project.',
221-
'Miscellaneous'),
220+
(
221+
master_doc,
222+
"Django-GraphQLJWT",
223+
"Django GraphQL JWT Documentation",
224+
author,
225+
"DjangoGraphQLJWT",
226+
"One line description of project.",
227+
"Miscellaneous",
228+
),
222229
]
223230

224231

@@ -237,4 +244,4 @@ def setup(app):
237244
# epub_uid = ''
238245

239246
# A list of files that should not be packed into the epub file.
240-
epub_exclude_files = ['search.html']
247+
epub_exclude_files = ["search.html"]

docs/decorators.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ As a shortcut, you can use the convenient ``user_passes_test()`` decorator which
3939
class Query(graphene.ObjectType):
4040
users = graphene.List(UserType)
4141

42-
@user_passes_test(lambda user: user.email.contains('@staff'))
42+
@user_passes_test(lambda user: user.email.contains("@staff"))
4343
def resolve_users(self, info, **kwargs):
4444
return get_user_model().objects.all()
4545

@@ -68,7 +68,7 @@ The decorator may also take an iterable of permissions, in which case the user m
6868
user_id = graphene.Int()
6969

7070
@classmethod
71-
@permission_required('auth.change_user')
71+
@permission_required("auth.change_user")
7272
def mutate(cls, root, info, user_id):
7373
...
7474

docs/quickstart.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ Add ``AuthenticationMiddleware`` middleware to your *MIDDLEWARE* settings:
2121
2222
MIDDLEWARE = [
2323
...
24-
'django.contrib.auth.middleware.AuthenticationMiddleware',
24+
"django.contrib.auth.middleware.AuthenticationMiddleware",
2525
...
2626
]
2727
2828
Add ``JSONWebTokenMiddleware`` middleware to your *GRAPHENE* settings::
2929

3030
GRAPHENE = {
31-
'SCHEMA': 'mysite.myschema.schema',
32-
'MIDDLEWARE': [
33-
'graphql_jwt.middleware.JSONWebTokenMiddleware',
31+
"SCHEMA": "mysite.myschema.schema",
32+
"MIDDLEWARE": [
33+
"graphql_jwt.middleware.JSONWebTokenMiddleware",
3434
],
3535
}
3636

3737
Add ``JSONWebTokenBackend`` backend to your *AUTHENTICATION_BACKENDS*::
3838

3939
AUTHENTICATION_BACKENDS = [
40-
'graphql_jwt.backends.JSONWebTokenBackend',
41-
'django.contrib.auth.backends.ModelBackend',
40+
"graphql_jwt.backends.JSONWebTokenBackend",
41+
"django.contrib.auth.backends.ModelBackend",
4242
]
4343

4444

docs/refresh_token.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Settings
1515
::
1616

1717
GRAPHQL_JWT = {
18-
'JWT_VERIFY_EXPIRATION': True,
19-
'JWT_EXPIRATION_DELTA': timedelta(minutes=5),
20-
'JWT_REFRESH_EXPIRATION_DELTA': timedelta(days=7),
18+
"JWT_VERIFY_EXPIRATION": True,
19+
"JWT_EXPIRATION_DELTA": timedelta(minutes=5),
20+
"JWT_REFRESH_EXPIRATION_DELTA": timedelta(days=7),
2121
}
2222

2323
It means that you need to refresh every 5 mins (``payload.exp``) and even you keep on refreshing token every 5 mins, you will still be logout in 7 days after the first token has been issued (``refreshExpiresIn``).
@@ -78,7 +78,7 @@ Add ``graphql_jwt.refresh_token`` to your *INSTALLED\_APPS*::
7878

7979
INSTALLED_APPS = [
8080
...
81-
'graphql_jwt.refresh_token.apps.RefreshTokenConfig',
81+
"graphql_jwt.refresh_token.apps.RefreshTokenConfig",
8282
...
8383
]
8484

@@ -88,10 +88,10 @@ Settings
8888
::
8989

9090
GRAPHQL_JWT = {
91-
'JWT_VERIFY_EXPIRATION': True,
92-
'JWT_LONG_RUNNING_REFRESH_TOKEN': True,
93-
'JWT_EXPIRATION_DELTA': timedelta(minutes=5),
94-
'JWT_REFRESH_EXPIRATION_DELTA': timedelta(days=7),
91+
"JWT_VERIFY_EXPIRATION": True,
92+
"JWT_LONG_RUNNING_REFRESH_TOKEN": True,
93+
"JWT_EXPIRATION_DELTA": timedelta(minutes=5),
94+
"JWT_REFRESH_EXPIRATION_DELTA": timedelta(days=7),
9595
}
9696

9797
It means that you need to refresh every 5 mins (``payload.exp``) and you need to replace your refresh token in 7 days after it has been issued (``refreshExpiresIn``).
@@ -166,9 +166,9 @@ Unlimited refresh
166166
Configure the ``JWT_REFRESH_EXPIRED_HANDLER`` setting that checks if the refresh token is expired::
167167

168168
GRAPHQL_JWT = {
169-
'JWT_VERIFY_EXPIRATION': True,
170-
'JWT_LONG_RUNNING_REFRESH_TOKEN': True,
171-
'JWT_REFRESH_EXPIRED_HANDLER': lambda orig_iat, context: False,
169+
"JWT_VERIFY_EXPIRATION": True,
170+
"JWT_LONG_RUNNING_REFRESH_TOKEN": True,
171+
"JWT_REFRESH_EXPIRED_HANDLER": lambda orig_iat, context: False,
172172
}
173173

174174
One time only use refresh token

0 commit comments

Comments
 (0)