You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-16Lines changed: 52 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ The structure is inspired by [cookiecutter-django](https://github.com/pydanny/co
16
16
Few important things:
17
17
18
18
* Linux / Ubuntu is our primary OS and things are tested for that. It will mostly not work on Mac & certainly not work on Windows.
19
-
* It uses Postgres as primary database.
19
+
* It uses Postgres as the primary database.
20
20
* It comes with GitHub Actions support, [based on that article](https://hacksoft.io/github-actions-in-action-setting-up-django-and-postgres/)
21
21
* It comes with examples for writing tests with fakes & factories, based on the following articles - <https://www.hacksoft.io/blog/improve-your-tests-django-fakes-and-factories>, <https://www.hacksoft.io/blog/improve-your-tests-django-fakes-and-factories-advanced-usage>
22
22
* It comes with [`whitenoise`](http://whitenoise.evans.io/en/stable/) setup.
We have removed the default authentication classes, since they were causing trouble.
46
+
The project is using <https://github.com/Styria-Digital/django-rest-framework-jwt> for having authentication via JWT capabilities.
47
47
48
-
## Authentication - General
48
+
### Settings
49
+
50
+
All JWT related settings are located in `config/settings/jwt.py`.
51
+
52
+
> ⚠️ We highly recommend reading the entire settings page from the project documentation - <https://styria-digital.github.io/django-rest-framework-jwt/#additional-settings> - to figure out your needs & the proper defaults for you!
53
+
54
+
The default settings also include the JWT token as a cookie.
55
+
56
+
The specific details about how the cookie is set, can be found here - <https://github.com/Styria-Digital/django-rest-framework-jwt/blob/master/src/rest_framework_jwt/compat.py#L43>
57
+
58
+
### APIs
59
+
60
+
The JWT related APIs are:
61
+
62
+
1.`/api/auth/jwt/login/`
63
+
1.`/api/auth/jwt/logout/`
64
+
65
+
The current implementation of the login API returns just the token:
This can be changed from `auth_jwt_response_payload_handler`.
74
+
75
+
76
+
### Requiring authentication
77
+
78
+
We follow this concept:
79
+
80
+
1. All APIs are public by default (no default authentication classes)
81
+
1. If you want a certain API to require authentication, you add the `ApiAuthMixin` to it.
82
+
83
+
## Authentication - Sessions
49
84
50
85
This project is using the already existing [**cookie-based session authentication**](https://docs.djangoproject.com/en/3.1/topics/auth/default/#how-to-log-a-user-in) in Django:
51
86
@@ -104,22 +139,15 @@ We have the following general cases:
104
139
1. If the backend is located on `*.domain.com` and the frontend is located on `*.domain.com`, the configuration is going to work out of the box.
105
140
1. If the backend is located on `somedomain.com` and the frontend is located on `anotherdomain.com`, then you'll need to set `SESSION_COOKIE_SAMESITE = 'None'` and `SESSION_COOKIE_SECURE = True`
106
141
107
-
### Reading list
108
-
109
-
Since cookies can be somewhat elusive, check the following urls:
110
-
111
-
1.<https://docs.djangoproject.com/en/3.1/ref/settings/#sessions> - It's a good idea to just read every description for `SESSION_*`
112
-
1.<https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies> - It's a good idea to read everything, several times.
113
-
114
-
## Authentication APIs
142
+
### APIs
115
143
116
-
1.`POST`<http://localhost:8000/api/auth/login/> requires JSON body with `email` and `password`.
117
-
1.`GET`<http://localhost:8000/api/auth/me/> returns the current user information, if the request is authenticated (has the corresponding `sessionid` cookie)
118
-
1.`GET` or `POST`<http://localhost:8000/api/auth/logout/> will remove the `sessionid` cookie, effectively logging you out.
144
+
1.`POST`to `/api/auth/session/login/` requires JSON body with `email` and `password`.
145
+
1.`GET`to `/api/auth/me/` returns the current user information, if the request is authenticated (has the corresponding `sessionid` cookie)
146
+
1.`GET` or `POST`to `/api/auth/logout/` will remove the `sessionid` cookie, effectively logging you out.
119
147
120
148
### `HTTP Only` / `SameSite`
121
149
122
-
The current implementation of `/auth/login` does 2 things:
150
+
The current implementation of `/api/auth/session/login` does 2 things:
123
151
124
152
1. Sets a `HTTP Only` cookie with the session id.
125
153
1. Returns the actual session id from the JSON payload.
@@ -128,6 +156,14 @@ The second thing is required, because Safari is not respecting the `SameSite = N
128
156
129
157
More on the issue here - <https://www.chromium.org/updates/same-site/incompatible-clients>
130
158
159
+
### Reading list
160
+
161
+
Since cookies can be somewhat elusive, check the following urls:
162
+
163
+
1.<https://docs.djangoproject.com/en/3.1/ref/settings/#sessions> - It's a good idea to just read every description for `SESSION_*`
164
+
1.<https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies> - It's a good idea to read everything, several times.
165
+
166
+
131
167
## Example List API
132
168
133
169
You can find the `UserListApi` in [`styleguide_example/users/apis.py`](https://github.com/HackSoftware/Styleguide-Example/blob/master/styleguide_example/users/apis.py#L12)
0 commit comments