Skip to content

Commit b63c576

Browse files
authored
Improve settings documentation (#1567)
Previously, it was unclear that the swappable model settings should always be set without a namespace, as the sub-section titles didn't include the required `OAUTH2_PROVIDER_` prefix. The warning at the top may not be noticed by people looking for a specific settings, and it was still unclear given the sub-section titles. Additionally, this documents the `OAUTH2_PROVIDER_ID_TOKEN_MODEL` and `OAUTH2_PROVIDER_GRANT_MODEL` settings, which were previously undocumented. Also, this corrects a mistake where `ACCESS_TOKEN_GENERATOR` was mentioned as the setting which enables the use of `SettingsScopes`; the actual setting is `SCOPES_BACKEND_CLASS`.
1 parent 839952f commit b63c576

File tree

1 file changed

+45
-35
lines changed

1 file changed

+45
-35
lines changed

docs/settings.rst

+45-35
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
Settings
22
========
33

4-
Our configurations are all namespaced under the ``OAUTH2_PROVIDER`` settings with the exception of
5-
``OAUTH2_PROVIDER_APPLICATION_MODEL``, ``OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL``, ``OAUTH2_PROVIDER_GRANT_MODEL``,
6-
``OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL``: this is because of the way Django currently implements
7-
swappable models. See `issue #90 <https://github.com/jazzband/django-oauth-toolkit/issues/90>`_ for details.
4+
Our configurations are all namespaced under the ``OAUTH2_PROVIDER`` settings, with the exception
5+
of the `List of non-namespaced settings`_.
86

97
For example:
108

@@ -24,32 +22,24 @@ For example:
2422
A big *thank you* to the guys from Django REST Framework for inspiring this.
2523

2624

27-
List of available settings
28-
--------------------------
25+
List of available settings within OAUTH2_PROVIDER
26+
-------------------------------------------------
2927

3028
ACCESS_TOKEN_EXPIRE_SECONDS
3129
~~~~~~~~~~~~~~~~~~~~~~~~~~~
32-
3330
Default: ``36000``
3431

3532
The number of seconds an access token remains valid. Requesting a protected
3633
resource after this duration will fail. Keep this value high enough so clients
3734
can cache the token for a reasonable amount of time.
3835

39-
ACCESS_TOKEN_MODEL
40-
~~~~~~~~~~~~~~~~~~
41-
The import string of the class (model) representing your access tokens. Overwrite
42-
this value if you wrote your own implementation (subclass of
43-
``oauth2_provider.models.AccessToken``).
44-
4536
ACCESS_TOKEN_GENERATOR
4637
~~~~~~~~~~~~~~~~~~~~~~
4738
Import path of a callable used to generate access tokens.
4839
``oauthlib.oauth2.rfc6749.tokens.random_token_generator`` is (normally) used if not provided.
4940

5041
ALLOWED_REDIRECT_URI_SCHEMES
5142
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52-
5343
Default: ``["http", "https"]``
5444

5545
A list of schemes that the ``redirect_uri`` field will be validated against.
@@ -65,7 +55,6 @@ a per-application basis.
6555

6656
ALLOW_URI_WILDCARDS
6757
~~~~~~~~~~~~~~~~~~~
68-
6958
Default: ``False``
7059

7160
SECURITY WARNING: Enabling this setting can introduce security vulnerabilities. Only enable
@@ -96,7 +85,6 @@ deployments for development previews and user acceptance testing.
9685

9786
ALLOWED_SCHEMES
9887
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99-
10088
Default: ``["https"]``
10189

10290
A list of schemes that the ``allowed_origins`` field will be validated against.
@@ -105,13 +93,6 @@ Adding ``"http"`` to the list is considered to be safe only for local developmen
10593
Note that `OAUTHLIB_INSECURE_TRANSPORT <https://oauthlib.readthedocs.io/en/latest/oauth2/security.html#envvar-OAUTHLIB_INSECURE_TRANSPORT>`_
10694
environment variable should be also set to allow HTTP origins.
10795

108-
109-
APPLICATION_MODEL
110-
~~~~~~~~~~~~~~~~~
111-
The import string of the class (model) representing your applications. Overwrite
112-
this value if you wrote your own implementation (subclass of
113-
``oauth2_provider.models.Application``).
114-
11596
AUTHORIZATION_CODE_EXPIRE_SECONDS
11697
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11798
Default: ``60``
@@ -214,12 +195,6 @@ period the application, the app then has only a consumed refresh token and the
214195
only recourse is to have the user re-authenticate. A suggested value, if this
215196
is enabled, is 2 minutes.
216197

217-
REFRESH_TOKEN_MODEL
218-
~~~~~~~~~~~~~~~~~~~
219-
The import string of the class (model) representing your refresh tokens. Overwrite
220-
this value if you wrote your own implementation (subclass of
221-
``oauth2_provider.models.RefreshToken``).
222-
223198
REFRESH_TOKEN_REUSE_PROTECTION
224199
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
225200
When this is set to ``True`` (default ``False``), and ``ROTATE_REFRESH_TOKEN`` is used, the server will check
@@ -257,15 +232,15 @@ Defaults to ``oauth2_provider.scopes.SettingsScopes``, which reads scopes throug
257232

258233
SCOPES
259234
~~~~~~
260-
.. note:: (0.12.0+) Only used if ``ACCESS_TOKEN_GENERATOR`` is set to the SettingsScopes default.
235+
.. note:: (0.12.0+) Only used if ``SCOPES_BACKEND_CLASS`` is set to the SettingsScopes default.
261236

262237
A dictionary mapping each scope name to its human description.
263238

264239
.. _settings_default_scopes:
265240

266241
DEFAULT_SCOPES
267242
~~~~~~~~~~~~~~
268-
.. note:: (0.12.0+) Only used if ``ACCESS_TOKEN_GENERATOR`` is set to the SettingsScopes default.
243+
.. note:: (0.12.0+) Only used if ``SCOPES_BACKEND_CLASS`` is set to the SettingsScopes default.
269244

270245
A list of scopes that should be returned by default.
271246
This is a subset of the keys of the ``SCOPES`` setting.
@@ -277,13 +252,13 @@ By default this is set to ``'__all__'`` meaning that the whole set of ``SCOPES``
277252
278253
READ_SCOPE
279254
~~~~~~~~~~
280-
.. note:: (0.12.0+) Only used if ``ACCESS_TOKEN_GENERATOR`` is set to the SettingsScopes default.
255+
.. note:: (0.12.0+) Only used if ``SCOPES_BACKEND_CLASS`` is set to the SettingsScopes default.
281256

282257
The name of the *read* scope.
283258

284259
WRITE_SCOPE
285260
~~~~~~~~~~~
286-
.. note:: (0.12.0+) Only used if ``ACCESS_TOKEN_GENERATOR`` is set to the SettingsScopes default.
261+
.. note:: (0.12.0+) Only used if ``SCOPES_BACKEND_CLASS`` is set to the SettingsScopes default.
287262

288263
The name of the *write* scope.
289264

@@ -340,7 +315,6 @@ Default: ``False``
340315

341316
Whether or not :doc:`oidc` support is enabled.
342317

343-
344318
OIDC_RSA_PRIVATE_KEY
345319
~~~~~~~~~~~~~~~~~~~~
346320
Default: ``""``
@@ -470,11 +444,47 @@ Time of sleep in seconds used by ``cleartokens`` management command between batc
470444
Set this to a non-zero value (e.g. ``0.1``) to add a pause between batch sizes to reduce system
471445
load when clearing large batches of expired tokens.
472446

447+
List of non-namespaced settings
448+
-------------------------------
449+
.. note::
450+
These settings must be set as top-level Django settings (outside of ``OAUTH2_PROVIDER``),
451+
because of the way Django currently implements swappable models.
452+
See `issue #90 <https://github.com/jazzband/django-oauth-toolkit/issues/90>`_ for details.
453+
454+
455+
OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL
456+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
457+
The import string of the class (model) representing your access tokens.
458+
Overwrite this value if you wrote your own implementation (subclass of
459+
``oauth2_provider.models.AccessToken``).
460+
461+
OAUTH2_PROVIDER_APPLICATION_MODEL
462+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
463+
The import string of the class (model) representing your applications.
464+
Overwrite this value if you wrote your own implementation (subclass of
465+
``oauth2_provider.models.Application``).
466+
467+
OAUTH2_PROVIDER_ID_TOKEN_MODEL
468+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
469+
The import string of the class (model) representing your OpenID Connect ID Token.
470+
Overwrite this value if you wrote your own implementation (subclass of
471+
``oauth2_provider.models.IDToken``).
472+
473+
OAUTH2_PROVIDER_GRANT_MODEL
474+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
475+
The import string of the class (model) representing your OAuth2 grants.
476+
Overwrite this value if you wrote your own implementation (subclass of
477+
``oauth2_provider.models.Grant``).
478+
479+
OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL
480+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
481+
The import string of the class (model) representing your refresh tokens.
482+
Overwrite this value if you wrote your own implementation (subclass of
483+
``oauth2_provider.models.RefreshToken``).
473484

474485
Settings imported from Django project
475486
-------------------------------------
476487

477488
USE_TZ
478489
~~~~~~
479-
480490
Used to determine whether or not to make token expire dates timezone aware.

0 commit comments

Comments
 (0)