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
@@ -7,7 +7,7 @@ The structure is inspired by [cookiecutter-django](https://github.com/pydanny/co
7
7
Few important things:
8
8
9
9
* Linux / Ubuntu is our primary OS and things are tested for that. It will mostly not work on Mac & certainly not work on Windows.
10
-
* It uses Postgres as primary database.
10
+
* It uses Postgres as the primary database.
11
11
* It comes with GitHub Actions support, [based on that article](https://hacksoft.io/github-actions-in-action-setting-up-django-and-postgres/)
12
12
* 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>
13
13
* It comes with [`whitenoise`](http://whitenoise.evans.io/en/stable/) setup.
We have removed the default authentication classes, since they were causing trouble.
37
+
The project is using <https://github.com/Styria-Digital/django-rest-framework-jwt> for having authentication via JWT capabilities.
38
38
39
-
## Authentication - General
39
+
### Settings
40
+
41
+
All JWT related settings are located in `config/settings/jwt.py`.
42
+
43
+
> ⚠️ 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!
44
+
45
+
The default settings also include the JWT token as a cookie.
46
+
47
+
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>
48
+
49
+
### APIs
50
+
51
+
The JWT related APIs are:
52
+
53
+
1.`/api/auth/jwt/login/`
54
+
1.`/api/auth/jwt/logout/`
55
+
56
+
The current implementation of the login API returns just the token:
This can be changed from `auth_jwt_response_payload_handler`.
65
+
66
+
67
+
### Requiring authentication
68
+
69
+
We follow this concept:
70
+
71
+
1. All APIs are public by default (no default authentication classes)
72
+
1. If you want a certain API to require authentication, you add the `ApiAuthMixin` to it.
73
+
74
+
## Authentication - Sessions
40
75
41
76
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:
42
77
@@ -95,22 +130,15 @@ We have the following general cases:
95
130
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.
96
131
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`
97
132
98
-
### Reading list
99
-
100
-
Since cookies can be somewhat elusive, check the following urls:
101
-
102
-
1.<https://docs.djangoproject.com/en/3.1/ref/settings/#sessions> - It's a good idea to just read every description for `SESSION_*`
103
-
1.<https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies> - It's a good idea to read everything, several times.
104
-
105
-
## Authentication APIs
133
+
### APIs
106
134
107
-
1.`POST`<http://localhost:8000/api/auth/login/> requires JSON body with `email` and `password`.
108
-
1.`GET`<http://localhost:8000/api/auth/me/> returns the current user information, if the request is authenticated (has the corresponding `sessionid` cookie)
109
-
1.`GET` or `POST`<http://localhost:8000/api/auth/logout/> will remove the `sessionid` cookie, effectively logging you out.
135
+
1.`POST`to `/api/auth/session/login/` requires JSON body with `email` and `password`.
136
+
1.`GET`to `/api/auth/me/` returns the current user information, if the request is authenticated (has the corresponding `sessionid` cookie)
137
+
1.`GET` or `POST`to `/api/auth/logout/` will remove the `sessionid` cookie, effectively logging you out.
110
138
111
139
### `HTTP Only` / `SameSite`
112
140
113
-
The current implementation of `/auth/login` does 2 things:
141
+
The current implementation of `/api/auth/session/login` does 2 things:
114
142
115
143
1. Sets a `HTTP Only` cookie with the session id.
116
144
1. Returns the actual session id from the JSON payload.
@@ -119,6 +147,14 @@ The second thing is required, because Safari is not respecting the `SameSite = N
119
147
120
148
More on the issue here - <https://www.chromium.org/updates/same-site/incompatible-clients>
121
149
150
+
### Reading list
151
+
152
+
Since cookies can be somewhat elusive, check the following urls:
153
+
154
+
1.<https://docs.djangoproject.com/en/3.1/ref/settings/#sessions> - It's a good idea to just read every description for `SESSION_*`
155
+
1.<https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies> - It's a good idea to read everything, several times.
156
+
157
+
122
158
## Example List API
123
159
124
160
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