File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ from django .apps import apps
2
+ from django .core import checks
3
+ from django .db import router
4
+
5
+ from .settings import oauth2_settings
6
+
7
+
8
+ @checks .register (checks .Tags .database )
9
+ def validate_token_configuration (app_configs , ** kwargs ):
10
+ breakpoint ()
11
+ databases = set (
12
+ router .db_for_write (apps .get_model (model ))
13
+ for model in (
14
+ oauth2_settings .ACCESS_TOKEN_MODEL ,
15
+ oauth2_settings .ID_TOKEN_MODEL ,
16
+ oauth2_settings .REFRESH_TOKEN_MODEL ,
17
+ )
18
+ )
19
+
20
+ # This is highly unlikely, but let's warn people just in case it does.
21
+ # If the tokens were allowed to be in different databases this would require all
22
+ # writes to have a transaction around each database. Instead, let's enforce that
23
+ # they all live together in one database.
24
+ # The tokens are not required to live in the default database provided the Django
25
+ # routers know the correct database for them.
26
+ if len (databases ) > 1 :
27
+ return [checks .Error ("The token models are expected to be stored in the same database." )]
28
+
29
+ return []
You can’t perform that action at this time.
0 commit comments