├── .gitignore
├── README.md
├── auth-nginx
├── Dockerfile
└── nginx.conf
├── auth-react
├── Dockerfile
├── README.md
├── package.json
├── public
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── robots.txt
├── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── axiosConfig.js
│ ├── index.css
│ ├── index.js
│ ├── logo.svg
│ ├── serviceWorker.js
│ └── setupTests.js
└── yarn.lock
├── authDjango
├── Dockerfile
├── Pipfile
├── Pipfile.lock
├── authApp
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-38.pyc
│ │ ├── admin.cpython-38.pyc
│ │ ├── models.cpython-38.pyc
│ │ ├── urls.cpython-38.pyc
│ │ └── views.cpython-38.pyc
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ │ └── __init__.cpython-38.pyc
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── authDjango
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-38.pyc
│ │ ├── settings.cpython-38.pyc
│ │ ├── urls.cpython-38.pyc
│ │ └── wsgi.cpython-38.pyc
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
└── requirements.txt
└── docker-compose.yaml
/.gitignore:
--------------------------------------------------------------------------------
1 | authreact/node_modules/
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DRF-React-Auth
2 | Respository for using session authentication with Django Rest Framework and React.
3 |
4 | Tutorial at https://medium.com/@kieron.mckenna/django-rest-framework-and-spa-session-authentication-with-docker-and-nginx-aa64871f29cd
5 |
6 |
7 | Get started with this command in the root directory
8 |
9 | docker-compose up
10 |
--------------------------------------------------------------------------------
/auth-nginx/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM nginx:latest
2 | COPY ./nginx.conf /etc/nginx/nginx.conf
--------------------------------------------------------------------------------
/auth-nginx/nginx.conf:
--------------------------------------------------------------------------------
1 | user www-data;
2 | worker_processes auto;
3 | pid /run/nginx.pid;
4 | include /etc/nginx/modules-enabled/*.conf;
5 | events {
6 | worker_connections 1024;
7 | }
8 | http {
9 | upstream auth-django {
10 | server auth-django:8000;
11 | }
12 | upstream auth-react {
13 | server auth-react:3000;
14 | }
15 | server {
16 | listen 80;
17 | server_name localhost 127.0.0.1;
18 | location /api {
19 | proxy_pass http://auth-django;
20 | proxy_set_header X-Forwarded-For $remote_addr;
21 | }
22 | location / {
23 | proxy_pass http://auth-react;
24 | proxy_set_header X-Forwarded-For $remote_addr;
25 | proxy_set_header Upgrade $http_upgrade;
26 | proxy_set_header Connection "upgrade";
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/auth-react/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:latest
2 | WORKDIR /code
3 | COPY package*.json /code/
4 | RUN npm install
5 | COPY . /code/
--------------------------------------------------------------------------------
/auth-react/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2 |
3 | ## Available Scripts
4 |
5 | In the project directory, you can run:
6 |
7 | ### `yarn start`
8 |
9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11 |
12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console.
14 |
15 | ### `yarn test`
16 |
17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19 |
20 | ### `yarn build`
21 |
22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance.
24 |
25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed!
27 |
28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29 |
30 | ### `yarn eject`
31 |
32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33 |
34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35 |
36 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37 |
38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39 |
40 | ## Learn More
41 |
42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43 |
44 | To learn React, check out the [React documentation](https://reactjs.org/).
45 |
46 | ### Code Splitting
47 |
48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49 |
50 | ### Analyzing the Bundle Size
51 |
52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53 |
54 | ### Making a Progressive Web App
55 |
56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57 |
58 | ### Advanced Configuration
59 |
60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61 |
62 | ### Deployment
63 |
64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65 |
66 | ### `yarn build` fails to minify
67 |
68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
69 |
--------------------------------------------------------------------------------
/auth-react/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "auth-react",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^4.2.4",
7 | "@testing-library/react": "^9.3.2",
8 | "@testing-library/user-event": "^7.1.2",
9 | "react": "^16.13.1",
10 | "react-dom": "^16.13.1",
11 | "react-scripts": "3.4.3"
12 | },
13 | "scripts": {
14 | "start": "react-scripts start",
15 | "build": "react-scripts build",
16 | "test": "react-scripts test",
17 | "eject": "react-scripts eject"
18 | },
19 | "eslintConfig": {
20 | "extends": "react-app"
21 | },
22 | "browserslist": {
23 | "production": [
24 | ">0.2%",
25 | "not dead",
26 | "not op_mini all"
27 | ],
28 | "development": [
29 | "last 1 chrome version",
30 | "last 1 firefox version",
31 | "last 1 safari version"
32 | ]
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/auth-react/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/auth-react/public/favicon.ico
--------------------------------------------------------------------------------
/auth-react/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/auth-react/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/auth-react/public/logo192.png
--------------------------------------------------------------------------------
/auth-react/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/auth-react/public/logo512.png
--------------------------------------------------------------------------------
/auth-react/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/auth-react/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/auth-react/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | }
4 |
5 | .App-logo {
6 | height: 40vmin;
7 | pointer-events: none;
8 | }
9 |
10 | @media (prefers-reduced-motion: no-preference) {
11 | .App-logo {
12 | animation: App-logo-spin infinite 20s linear;
13 | }
14 | }
15 |
16 | .App-header {
17 | background-color: #282c34;
18 | min-height: 100vh;
19 | display: flex;
20 | flex-direction: column;
21 | align-items: center;
22 | justify-content: center;
23 | font-size: calc(10px + 2vmin);
24 | color: white;
25 | }
26 |
27 | .App-link {
28 | color: #61dafb;
29 | }
30 |
31 | @keyframes App-logo-spin {
32 | from {
33 | transform: rotate(0deg);
34 | }
35 | to {
36 | transform: rotate(360deg);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/auth-react/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import './App.css';
3 | // Notice we're importing from the file we created, not the axios package
4 | import axios from './axiosConfig';
5 | export default class App extends Component {
6 | constructor(props){
7 | super(props)
8 | this.state = {
9 | username: '',
10 | password: '',
11 | auth: null,
12 | endpoint: null
13 | }
14 | }
15 | setCSRF = () => {
16 | axios.get('api/set-csrf/').then(res => console.log(res))
17 | }
18 | handleChange = (e) => {
19 | this.setState({[e.target.name]: e.target.value})
20 | }
21 | handleSubmit = (event) => {
22 | event.preventDefault();
23 | axios.post('/api/login/',
24 | {username: this.state.username,
25 | password: this.state.password}
26 | ).then(res => {
27 | this.setState({auth: true})
28 | }).catch(res => this.setState({auth: false}))
29 | }
30 | testEndpoint = () => {
31 | axios.get('/api/test-auth/').then(res => this.setState(
32 | {endpoint: true}))
33 | .catch(res => this.setState({endpoint: false}))
34 | }
35 | render() {
36 | return
37 |
38 |
39 |
40 |
47 |
48 |
49 | {this.state.auth === null ? '' : (this.state.auth ? 'Login successful' : 'Login Failed' )}
50 |
51 |
52 |
53 |
{this.state.endpoint === null ? '' : (this.state.endpoint ? 'Successful Request' : 'Request Rejected')}
54 |
55 | };
56 | }
--------------------------------------------------------------------------------
/auth-react/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { render } from '@testing-library/react';
3 | import App from './App';
4 |
5 | test('renders learn react link', () => {
6 | const { getByText } = render();
7 | const linkElement = getByText(/learn react/i);
8 | expect(linkElement).toBeInTheDocument();
9 | });
10 |
--------------------------------------------------------------------------------
/auth-react/src/axiosConfig.js:
--------------------------------------------------------------------------------
1 | import axios from 'axios'
2 | axios.defaults.xsrfHeaderName = "X-CSRFToken"
3 | axios.defaults.xsrfCookieName = 'csrftoken'
4 | axios.defaults.withCredentials = true
5 | export default axios
--------------------------------------------------------------------------------
/auth-react/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12 | monospace;
13 | }
14 |
--------------------------------------------------------------------------------
/auth-react/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 |
7 | ReactDOM.render(
8 |
9 |
10 | ,
11 | document.getElementById('root')
12 | );
13 |
14 | // If you want your app to work offline and load faster, you can change
15 | // unregister() to register() below. Note this comes with some pitfalls.
16 | // Learn more about service workers: https://bit.ly/CRA-PWA
17 | serviceWorker.unregister();
18 |
--------------------------------------------------------------------------------
/auth-react/src/logo.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/auth-react/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.0/8 are considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl, {
104 | headers: { 'Service-Worker': 'script' },
105 | })
106 | .then(response => {
107 | // Ensure service worker exists, and that we really are getting a JS file.
108 | const contentType = response.headers.get('content-type');
109 | if (
110 | response.status === 404 ||
111 | (contentType != null && contentType.indexOf('javascript') === -1)
112 | ) {
113 | // No service worker found. Probably a different app. Reload the page.
114 | navigator.serviceWorker.ready.then(registration => {
115 | registration.unregister().then(() => {
116 | window.location.reload();
117 | });
118 | });
119 | } else {
120 | // Service worker found. Proceed as normal.
121 | registerValidSW(swUrl, config);
122 | }
123 | })
124 | .catch(() => {
125 | console.log(
126 | 'No internet connection found. App is running in offline mode.'
127 | );
128 | });
129 | }
130 |
131 | export function unregister() {
132 | if ('serviceWorker' in navigator) {
133 | navigator.serviceWorker.ready
134 | .then(registration => {
135 | registration.unregister();
136 | })
137 | .catch(error => {
138 | console.error(error.message);
139 | });
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/auth-react/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom/extend-expect';
6 |
--------------------------------------------------------------------------------
/authDjango/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.8.3
2 |
3 | ENV PYTHONUNBUFFERED 1
4 |
5 | RUN mkdir /code
6 | WORKDIR /code
7 | COPY requirements.txt /code/
8 | RUN pip install -r requirements.txt
9 |
10 |
11 | COPY . /code/
12 |
--------------------------------------------------------------------------------
/authDjango/Pipfile:
--------------------------------------------------------------------------------
1 | [[source]]
2 | name = "pypi"
3 | url = "https://pypi.org/simple"
4 | verify_ssl = true
5 |
6 | [dev-packages]
7 |
8 | [packages]
9 | django = "*"
10 | djangorestframework = "*"
11 | psycopg2-binary = "*"
12 |
13 | [requires]
14 | python_version = "3.8"
15 |
--------------------------------------------------------------------------------
/authDjango/Pipfile.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_meta": {
3 | "hash": {
4 | "sha256": "0fa67d19b8d73b10a1d75fea99d3c42e189d470572643574ffdafa3fa070c966"
5 | },
6 | "pipfile-spec": 6,
7 | "requires": {
8 | "python_version": "3.8"
9 | },
10 | "sources": [
11 | {
12 | "name": "pypi",
13 | "url": "https://pypi.org/simple",
14 | "verify_ssl": true
15 | }
16 | ]
17 | },
18 | "default": {
19 | "asgiref": {
20 | "hashes": [
21 | "sha256:7e51911ee147dd685c3c8b805c0ad0cb58d360987b56953878f8c06d2d1c6f1a",
22 | "sha256:9fc6fb5d39b8af147ba40765234fa822b39818b12cc80b35ad9b0cef3a476aed"
23 | ],
24 | "markers": "python_version >= '3.5'",
25 | "version": "==3.2.10"
26 | },
27 | "django": {
28 | "hashes": [
29 | "sha256:59c8125ca873ed3bdae9c12b146fbbd6ed8d0f743e4cf5f5817af50c51f1fc2f",
30 | "sha256:b5fbb818e751f660fa2d576d9f40c34a4c615c8b48dd383f5216e609f383371f"
31 | ],
32 | "index": "pypi",
33 | "version": "==3.1.1"
34 | },
35 | "djangorestframework": {
36 | "hashes": [
37 | "sha256:6dd02d5a4bd2516fb93f80360673bf540c3b6641fec8766b1da2870a5aa00b32",
38 | "sha256:8b1ac62c581dbc5799b03e535854b92fc4053ecfe74bad3f9c05782063d4196b"
39 | ],
40 | "index": "pypi",
41 | "version": "==3.11.1"
42 | },
43 | "psycopg2-binary": {
44 | "hashes": [
45 | "sha256:0deac2af1a587ae12836aa07970f5cb91964f05a7c6cdb69d8425ff4c15d4e2c",
46 | "sha256:0e4dc3d5996760104746e6cfcdb519d9d2cd27c738296525d5867ea695774e67",
47 | "sha256:11b9c0ebce097180129e422379b824ae21c8f2a6596b159c7659e2e5a00e1aa0",
48 | "sha256:1fabed9ea2acc4efe4671b92c669a213db744d2af8a9fc5d69a8e9bc14b7a9db",
49 | "sha256:2dac98e85565d5688e8ab7bdea5446674a83a3945a8f416ad0110018d1501b94",
50 | "sha256:42ec1035841b389e8cc3692277a0bd81cdfe0b65d575a2c8862cec7a80e62e52",
51 | "sha256:6a32f3a4cb2f6e1a0b15215f448e8ce2da192fd4ff35084d80d5e39da683e79b",
52 | "sha256:7312e931b90fe14f925729cde58022f5d034241918a5c4f9797cac62f6b3a9dd",
53 | "sha256:7d92a09b788cbb1aec325af5fcba9fed7203897bbd9269d5691bb1e3bce29550",
54 | "sha256:833709a5c66ca52f1d21d41865a637223b368c0ee76ea54ca5bad6f2526c7679",
55 | "sha256:8cd0fb36c7412996859cb4606a35969dd01f4ea34d9812a141cd920c3b18be77",
56 | "sha256:950bc22bb56ee6ff142a2cb9ee980b571dd0912b0334aa3fe0fe3788d860bea2",
57 | "sha256:a0c50db33c32594305b0ef9abc0cb7db13de7621d2cadf8392a1d9b3c437ef77",
58 | "sha256:a0eb43a07386c3f1f1ebb4dc7aafb13f67188eab896e7397aa1ee95a9c884eb2",
59 | "sha256:aaa4213c862f0ef00022751161df35804127b78adf4a2755b9f991a507e425fd",
60 | "sha256:ac0c682111fbf404525dfc0f18a8b5f11be52657d4f96e9fcb75daf4f3984859",
61 | "sha256:ad20d2eb875aaa1ea6d0f2916949f5c08a19c74d05b16ce6ebf6d24f2c9f75d1",
62 | "sha256:b4afc542c0ac0db720cf516dd20c0846f71c248d2b3d21013aa0d4ef9c71ca25",
63 | "sha256:b8a3715b3c4e604bcc94c90a825cd7f5635417453b253499664f784fc4da0152",
64 | "sha256:ba28584e6bca48c59eecbf7efb1576ca214b47f05194646b081717fa628dfddf",
65 | "sha256:ba381aec3a5dc29634f20692349d73f2d21f17653bda1decf0b52b11d694541f",
66 | "sha256:bd1be66dde2b82f80afb9459fc618216753f67109b859a361cf7def5c7968729",
67 | "sha256:c2507d796fca339c8fb03216364cca68d87e037c1f774977c8fc377627d01c71",
68 | "sha256:cec7e622ebc545dbb4564e483dd20e4e404da17ae07e06f3e780b2dacd5cee66",
69 | "sha256:d14b140a4439d816e3b1229a4a525df917d6ea22a0771a2a78332273fd9528a4",
70 | "sha256:d1b4ab59e02d9008efe10ceabd0b31e79519da6fb67f7d8e8977118832d0f449",
71 | "sha256:d5227b229005a696cc67676e24c214740efd90b148de5733419ac9aaba3773da",
72 | "sha256:e1f57aa70d3f7cc6947fd88636a481638263ba04a742b4a37dd25c373e41491a",
73 | "sha256:e74a55f6bad0e7d3968399deb50f61f4db1926acf4a6d83beaaa7df986f48b1c",
74 | "sha256:e82aba2188b9ba309fd8e271702bd0d0fc9148ae3150532bbb474f4590039ffb",
75 | "sha256:ee69dad2c7155756ad114c02db06002f4cded41132cc51378e57aad79cc8e4f4",
76 | "sha256:f5ab93a2cb2d8338b1674be43b442a7f544a0971da062a5da774ed40587f18f5"
77 | ],
78 | "index": "pypi",
79 | "version": "==2.8.6"
80 | },
81 | "pytz": {
82 | "hashes": [
83 | "sha256:a494d53b6d39c3c6e44c3bec237336e14305e4f29bbf800b599253057fbb79ed",
84 | "sha256:c35965d010ce31b23eeb663ed3cc8c906275d6be1a34393a1d73a41febf4a048"
85 | ],
86 | "version": "==2020.1"
87 | },
88 | "sqlparse": {
89 | "hashes": [
90 | "sha256:022fb9c87b524d1f7862b3037e541f68597a730a8843245c349fc93e1643dc4e",
91 | "sha256:e162203737712307dfe78860cc56c8da8a852ab2ee33750e33aeadf38d12c548"
92 | ],
93 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
94 | "version": "==0.3.1"
95 | }
96 | },
97 | "develop": {}
98 | }
99 |
--------------------------------------------------------------------------------
/authDjango/authApp/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authApp/__init__.py
--------------------------------------------------------------------------------
/authDjango/authApp/__pycache__/__init__.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authApp/__pycache__/__init__.cpython-38.pyc
--------------------------------------------------------------------------------
/authDjango/authApp/__pycache__/admin.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authApp/__pycache__/admin.cpython-38.pyc
--------------------------------------------------------------------------------
/authDjango/authApp/__pycache__/models.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authApp/__pycache__/models.cpython-38.pyc
--------------------------------------------------------------------------------
/authDjango/authApp/__pycache__/urls.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authApp/__pycache__/urls.cpython-38.pyc
--------------------------------------------------------------------------------
/authDjango/authApp/__pycache__/views.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authApp/__pycache__/views.cpython-38.pyc
--------------------------------------------------------------------------------
/authDjango/authApp/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | # Register your models here.
4 |
--------------------------------------------------------------------------------
/authDjango/authApp/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class AuthConfig(AppConfig):
5 | name = 'auth'
6 |
--------------------------------------------------------------------------------
/authDjango/authApp/migrations/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authApp/migrations/__init__.py
--------------------------------------------------------------------------------
/authDjango/authApp/migrations/__pycache__/__init__.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authApp/migrations/__pycache__/__init__.cpython-38.pyc
--------------------------------------------------------------------------------
/authDjango/authApp/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 | # Create your models here.
4 |
--------------------------------------------------------------------------------
/authDjango/authApp/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/authDjango/authApp/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path
2 | from .views import set_csrf_token, login_view, CheckAuth
3 |
4 | urlpatterns = [
5 | path('set-csrf/', set_csrf_token, name='Set-CSRF'),
6 | path('login/', login_view, name='Login'),
7 | path('test-auth/', CheckAuth.as_view(), name='check-auth')
8 | ]
9 |
--------------------------------------------------------------------------------
/authDjango/authApp/views.py:
--------------------------------------------------------------------------------
1 |
2 | import json
3 | from django.contrib.auth import authenticate, login
4 | from django.views.decorators.http import require_POST
5 | from django.views.decorators.csrf import ensure_csrf_cookie
6 | from django.http import JsonResponse
7 | from rest_framework.views import APIView
8 | from rest_framework.authentication import SessionAuthentication
9 | from rest_framework.response import Response
10 |
11 |
12 |
13 |
14 | @ensure_csrf_cookie
15 | def set_csrf_token(request):
16 | """
17 | This will be `/api/set-csrf-cookie/` on `urls.py`
18 | """
19 | return JsonResponse({"details": "CSRF cookie set"})
20 |
21 |
22 | @require_POST
23 | def login_view(request):
24 | """
25 | This will be `/api/login/` on `urls.py`
26 | """
27 | data = json.loads(request.body)
28 | username = data.get('username')
29 | password = data.get('password')
30 | if username is None or password is None:
31 | return JsonResponse({
32 | "errors": {
33 | "__all__": "Please enter both username and password"
34 | }
35 | }, status=400)
36 | user = authenticate(username=username, password=password)
37 | if user is not None:
38 | login(request, user)
39 | return JsonResponse({"detail": "Success"})
40 | return JsonResponse(
41 | {"detail": "Invalid credentials"},
42 | status=400,
43 | )
44 |
45 |
46 | class CheckAuth(APIView):
47 | authentication_classes = [SessionAuthentication]
48 |
49 | def get(self, request):
50 | return Response({'detail': 'You\'re Authenticated'})
--------------------------------------------------------------------------------
/authDjango/authDjango/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authDjango/__init__.py
--------------------------------------------------------------------------------
/authDjango/authDjango/__pycache__/__init__.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authDjango/__pycache__/__init__.cpython-38.pyc
--------------------------------------------------------------------------------
/authDjango/authDjango/__pycache__/settings.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authDjango/__pycache__/settings.cpython-38.pyc
--------------------------------------------------------------------------------
/authDjango/authDjango/__pycache__/urls.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authDjango/__pycache__/urls.cpython-38.pyc
--------------------------------------------------------------------------------
/authDjango/authDjango/__pycache__/wsgi.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kieronjmckenna/DRF-React-Auth/5a545aac3d52c4415b5010ae47e8df081d80fdae/authDjango/authDjango/__pycache__/wsgi.cpython-38.pyc
--------------------------------------------------------------------------------
/authDjango/authDjango/asgi.py:
--------------------------------------------------------------------------------
1 | """
2 | ASGI config for authDjango project.
3 |
4 | It exposes the ASGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.asgi import get_asgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'authDjango.settings')
15 |
16 | application = get_asgi_application()
17 |
--------------------------------------------------------------------------------
/authDjango/authDjango/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for authDjango project.
3 |
4 | Generated by 'django-admin startproject' using Django 3.1.1.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.1/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/3.1/ref/settings/
11 | """
12 |
13 | from pathlib import Path
14 |
15 | # Build paths inside the project like this: BASE_DIR / 'subdir'.
16 | BASE_DIR = Path(__file__).resolve().parent.parent
17 |
18 |
19 | # Quick-start development settings - unsuitable for production
20 | # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
21 |
22 | # SECURITY WARNING: keep the secret key used in production secret!
23 | SECRET_KEY = 'jug4j_!ryaa8fw2mwu*s8g&lwvttu&%2=*v6%my8wjp4*b*4r$'
24 |
25 | # SECURITY WARNING: don't run with debug turned on in production!
26 | DEBUG = True
27 |
28 | ALLOWED_HOSTS = ['*']
29 |
30 |
31 | # Application definition
32 |
33 | INSTALLED_APPS = [
34 | 'django.contrib.admin',
35 | 'django.contrib.auth',
36 | 'django.contrib.contenttypes',
37 | 'django.contrib.sessions',
38 | 'django.contrib.messages',
39 | 'django.contrib.staticfiles',
40 | 'rest_framework',
41 | 'authApp'
42 | ]
43 |
44 | MIDDLEWARE = [
45 | 'django.middleware.security.SecurityMiddleware',
46 | 'django.contrib.sessions.middleware.SessionMiddleware',
47 | 'django.middleware.common.CommonMiddleware',
48 | 'django.middleware.csrf.CsrfViewMiddleware',
49 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
50 | 'django.contrib.messages.middleware.MessageMiddleware',
51 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
52 | ]
53 |
54 | ROOT_URLCONF = 'authDjango.urls'
55 |
56 | TEMPLATES = [
57 | {
58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
59 | 'DIRS': [],
60 | 'APP_DIRS': True,
61 | 'OPTIONS': {
62 | 'context_processors': [
63 | 'django.template.context_processors.debug',
64 | 'django.template.context_processors.request',
65 | 'django.contrib.auth.context_processors.auth',
66 | 'django.contrib.messages.context_processors.messages',
67 | ],
68 | },
69 | },
70 | ]
71 |
72 | WSGI_APPLICATION = 'authDjango.wsgi.application'
73 |
74 |
75 | # Database
76 | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases
77 |
78 | DATABASES = {
79 | 'default': {
80 | 'ENGINE': 'django.db.backends.postgresql',
81 | 'NAME': 'authTesting',
82 | 'USER': 'postgres',
83 | 'PASSWORD': '...',
84 | # 'HOST': 'localhost',
85 | 'HOST': 'host.docker.internal',
86 | 'PORT': 5433,
87 | }
88 | }
89 |
90 |
91 | # Password validation
92 | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
93 |
94 | AUTH_PASSWORD_VALIDATORS = [
95 | {
96 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
97 | },
98 | {
99 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
100 | },
101 | {
102 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
103 | },
104 | {
105 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
106 | },
107 | ]
108 |
109 |
110 | # Internationalization
111 | # https://docs.djangoproject.com/en/3.1/topics/i18n/
112 |
113 | LANGUAGE_CODE = 'en-us'
114 |
115 | TIME_ZONE = 'UTC'
116 |
117 | USE_I18N = True
118 |
119 | USE_L10N = True
120 |
121 | USE_TZ = True
122 |
123 |
124 | # Static files (CSS, JavaScript, Images)
125 | # https://docs.djangoproject.com/en/3.1/howto/static-files/
126 |
127 | STATIC_URL = '/api/static/'
128 |
129 |
130 | REST_FRAMEWORK = {
131 | 'DEFAULT_AUTHENTICATION_CLASSES': (
132 | 'rest_framework.authentication.SessionAuthentication'
133 | ),
134 | 'DEFAULT_PERMISSION_CLASSES': [
135 | 'rest_framework.permissions.IsAuthenticated'
136 | ]
137 | }
--------------------------------------------------------------------------------
/authDjango/authDjango/urls.py:
--------------------------------------------------------------------------------
1 |
2 | from django.contrib import admin
3 | from django.urls import path, include
4 |
5 |
6 | urlpatterns = [
7 | path('api/admin/', admin.site.urls),
8 | path('api/', include('authApp.urls'))
9 | ]
10 |
--------------------------------------------------------------------------------
/authDjango/authDjango/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for authDjango project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'authDjango.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/authDjango/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """Django's command-line utility for administrative tasks."""
3 | import os
4 | import sys
5 |
6 |
7 | def main():
8 | """Run administrative tasks."""
9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'authDjango.settings')
10 | try:
11 | from django.core.management import execute_from_command_line
12 | except ImportError as exc:
13 | raise ImportError(
14 | "Couldn't import Django. Are you sure it's installed and "
15 | "available on your PYTHONPATH environment variable? Did you "
16 | "forget to activate a virtual environment?"
17 | ) from exc
18 | execute_from_command_line(sys.argv)
19 |
20 |
21 | if __name__ == '__main__':
22 | main()
23 |
--------------------------------------------------------------------------------
/authDjango/requirements.txt:
--------------------------------------------------------------------------------
1 | asgiref==3.2.10
2 | Django==3.1.1
3 | djangorestframework==3.11.1
4 | psycopg2-binary==2.8.6
5 | pytz==2020.1
6 | sqlparse==0.3.1
7 |
--------------------------------------------------------------------------------
/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | version: '3.7'
2 | services:
3 | # NEW
4 | reverse_proxy:
5 | build: ./auth-nginx
6 | volumes:
7 | - ./auth-nginx/nginx.conf:/etc/nginx/nginx.conf
8 | ports:
9 | - 80:80
10 | depends_on:
11 | - auth-django
12 | - auth-react
13 | auth-django:
14 | tty: true
15 | build: ./authDjango
16 | command: python manage.py runserver 0.0.0.0:8000
17 | volumes:
18 | - ./authDjango:/code
19 | # ports:
20 | # - 8000:8000
21 | # NEW
22 | expose:
23 | - 8000
24 | auth-react:
25 | tty: true
26 | build: ./auth-react
27 | command: npm start
28 | # ports:
29 | # - 3000:3000
30 | # NEW
31 | expose:
32 | - 3000
33 | image: no-react
34 | volumes:
35 | - ./auth-react:/code
36 |
--------------------------------------------------------------------------------