├── .env.example
├── .eslintignore
├── .eslintrc.json
├── .github
└── workflows
│ └── node.js.yml
├── .gitignore
├── .prettierignore
├── .prettierrc.json
├── LICENSE
├── README.md
├── client
├── .env.example
├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── robots.txt
└── src
│ ├── App.js
│ ├── App.test.js
│ ├── GlobalStyle.js
│ ├── common
│ ├── Navigation.js
│ └── Page.js
│ ├── index.js
│ ├── pages
│ ├── Home.js
│ ├── Login.js
│ └── Profile.js
│ ├── serviceWorker.js
│ └── setupTests.js
├── nodemon.json
├── package-lock.json
├── package.json
└── server.js
/.env.example:
--------------------------------------------------------------------------------
1 | PORT=3001
2 | GITHUB_CLIENT_ID=xxx
3 | GITHUB_CLIENT_SECRET=xxx
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | **/node_modules/
2 | **/build/
3 | **/storybook-static/
4 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true,
4 | "commonjs": true,
5 | "es6": true,
6 | "node": true
7 | },
8 | "extends": [
9 | "react-app",
10 | "eslint:recommended",
11 | "plugin:react/recommended",
12 | "prettier"
13 | ],
14 | "parserOptions": {
15 | "ecmaFeatures": {
16 | "jsx": true
17 | },
18 | "ecmaVersion": 12,
19 | "sourceType": "module"
20 | },
21 | "settings": {
22 | "react": {
23 | "version": "latest"
24 | }
25 | },
26 | "rules": {
27 | "no-unused-vars": [
28 | "warn",
29 | { "vars": "all", "args": "after-used", "ignoreRestSiblings": true }
30 | ],
31 | "import/no-anonymous-default-export": "off"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/.github/workflows/node.js.yml:
--------------------------------------------------------------------------------
1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3 |
4 | name: Node.js CI
5 |
6 | on:
7 | push:
8 | branches: [main]
9 | pull_request:
10 | branches: [main]
11 |
12 | jobs:
13 | build:
14 | runs-on: ubuntu-latest
15 |
16 | strategy:
17 | matrix:
18 | node-version: [10.x, 12.x, 14.x]
19 |
20 | steps:
21 | - uses: actions/checkout@v2
22 | - name: Use Node.js ${{ matrix.node-version }}
23 | uses: actions/setup-node@v1
24 | with:
25 | node-version: ${{ matrix.node-version }}
26 | - run: npm ci
27 | - run: npm run build --if-present
28 | - run: npm test
29 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | lerna-debug.log*
8 |
9 | # Diagnostic reports (https://nodejs.org/api/report.html)
10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11 |
12 | # Runtime data
13 | pids
14 | *.pid
15 | *.seed
16 | *.pid.lock
17 |
18 | # Directory for instrumented libs generated by jscoverage/JSCover
19 | lib-cov
20 |
21 | # Coverage directory used by tools like istanbul
22 | coverage
23 | *.lcov
24 |
25 | # nyc test coverage
26 | .nyc_output
27 |
28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29 | .grunt
30 |
31 | # Bower dependency directory (https://bower.io/)
32 | bower_components
33 |
34 | # node-waf configuration
35 | .lock-wscript
36 |
37 | # Compiled binary addons (https://nodejs.org/api/addons.html)
38 | build/Release
39 |
40 | # Dependency directories
41 | node_modules/
42 | jspm_packages/
43 |
44 | # TypeScript v1 declaration files
45 | typings/
46 |
47 | # TypeScript cache
48 | *.tsbuildinfo
49 |
50 | # Optional npm cache directory
51 | .npm
52 |
53 | # Optional eslint cache
54 | .eslintcache
55 |
56 | # Microbundle cache
57 | .rpt2_cache/
58 | .rts2_cache_cjs/
59 | .rts2_cache_es/
60 | .rts2_cache_umd/
61 |
62 | # Optional REPL history
63 | .node_repl_history
64 |
65 | # Output of 'npm pack'
66 | *.tgz
67 |
68 | # Yarn Integrity file
69 | .yarn-integrity
70 |
71 | # dotenv environment variables file
72 | .env
73 | .env.test
74 |
75 | # parcel-bundler cache (https://parceljs.org/)
76 | .cache
77 |
78 | # Next.js build output
79 | .next
80 |
81 | # Nuxt.js build / generate output
82 | .nuxt
83 | dist
84 |
85 | # Gatsby files
86 | .cache/
87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js
88 | # https://nextjs.org/blog/next-9-1#public-directory-support
89 | # public
90 |
91 | # vuepress build output
92 | .vuepress/dist
93 |
94 | # Serverless directories
95 | .serverless/
96 |
97 | # FuseBox cache
98 | .fusebox/
99 |
100 | # DynamoDB Local files
101 | .dynamodb/
102 |
103 | # TernJS port file
104 | .tern-port
105 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | # Ignore artifacts:
2 | build/
3 | coverage/
4 | storybook-static/
--------------------------------------------------------------------------------
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Leon Machens
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # hello oauth
4 |
5 | A small demo of oauth with GitHub and pseudo-authentication with JWTs.
6 |
7 | ## Getting started
8 |
9 | - Clone this repo
10 | - `cd` into the project directory and run `npm install`
11 | - start server and client in development mode with `npm run dev`
12 | - Checkout the `github-oauth` and `jwt` branches. Happy hacking!
13 |
--------------------------------------------------------------------------------
/client/.env.example:
--------------------------------------------------------------------------------
1 | REACT_APP_GITHUB_CLIENT_ID=xxx
--------------------------------------------------------------------------------
/client/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 | /storybook-static
14 |
15 | # misc
16 | .DS_Store
17 | .env.local
18 | .env.development.local
19 | .env.test.local
20 | .env.production.local
21 |
22 | npm-debug.log*
23 | yarn-debug.log*
24 | yarn-error.log*
25 |
--------------------------------------------------------------------------------
/client/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 | ### `npm 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 | ### `npm 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 | ### `npm run 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 | ### `npm run 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 | ### `npm run 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 |
--------------------------------------------------------------------------------
/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@babel/core": "^7.12.8",
7 | "@testing-library/jest-dom": "^5.11.6",
8 | "@testing-library/react": "^11.2.2",
9 | "@testing-library/user-event": "^12.2.2",
10 | "react": "^17.0.1",
11 | "react-dom": "^17.0.1",
12 | "react-is": "^17.0.1",
13 | "react-router-dom": "5.2.0",
14 | "react-scripts": "4.0.1",
15 | "styled-components": "5.2.1"
16 | },
17 | "scripts": {
18 | "start": "react-scripts start",
19 | "build": "react-scripts build",
20 | "test:watch": "react-scripts test",
21 | "test": "react-scripts test --watchAll=false",
22 | "eject": "react-scripts eject"
23 | },
24 | "browserslist": {
25 | "production": [
26 | ">0.2%",
27 | "not dead",
28 | "not op_mini all"
29 | ],
30 | "development": [
31 | "last 1 chrome version",
32 | "last 1 firefox version",
33 | "last 1 safari version"
34 | ]
35 | },
36 | "proxy": "http://localhost:3001"
37 | }
38 |
--------------------------------------------------------------------------------
/client/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jamarob/oauth-demo/35c91c5ab488267687960bdea1d1298db02c9685/client/public/favicon.ico
--------------------------------------------------------------------------------
/client/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | OAuth example
28 |
29 |
30 |
31 |
32 |
33 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/client/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jamarob/oauth-demo/35c91c5ab488267687960bdea1d1298db02c9685/client/public/logo192.png
--------------------------------------------------------------------------------
/client/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jamarob/oauth-demo/35c91c5ab488267687960bdea1d1298db02c9685/client/public/logo512.png
--------------------------------------------------------------------------------
/client/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "CRA-With-API",
3 | "name": "CRA-With-API 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 |
--------------------------------------------------------------------------------
/client/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/client/src/App.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import GlobalStyle from "./GlobalStyle";
3 | import {
4 | BrowserRouter as Router,
5 | Switch,
6 | Route,
7 | Redirect,
8 | } from "react-router-dom";
9 | import Home from "./pages/Home";
10 | import Profile from "./pages/Profile";
11 | import Login from "./pages/Login";
12 |
13 | export default function App() {
14 | return (
15 |
16 |
17 |
18 |
19 |
20 |
21 | } />
22 |
23 |
24 | );
25 | }
26 |
--------------------------------------------------------------------------------
/client/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { render, screen } from "@testing-library/react";
3 | import App from "./App";
4 |
5 | test("renders oauth heading", () => {
6 | render();
7 | const heading = screen.getByRole("heading", { name: /hello oauth/i });
8 | expect(heading).toBeInTheDocument();
9 | });
10 |
--------------------------------------------------------------------------------
/client/src/GlobalStyle.js:
--------------------------------------------------------------------------------
1 | import { createGlobalStyle } from "styled-components";
2 |
3 | export default createGlobalStyle`
4 | :root {
5 | --blue-main: #193251;
6 | --blue-75: #7589A2;
7 | --blue-50: #E0E4E8;
8 | --blue-25: #F8F8F8;
9 |
10 | --orange-main: #FF5A36;
11 | --orange-75: #FF9C86;
12 | --orange-50: #FFBDAF;
13 | --orange-25: #FFDED7;
14 |
15 | --shadow-blue: 0px 2px 11px 0px rgba(25, 50, 81, 0.2);
16 |
17 | --shadow-orange: 0px 4px 10px #ff5a3666;
18 |
19 | --border-blue: 1px solid var(--blue-50);
20 |
21 | --size-xs: 4px;
22 | --size-s: 8px;
23 | --size-m: 12px;
24 | --size-l: 16px;
25 | --size-xl: 24px;
26 | --size-xxl: 32px;
27 | }
28 |
29 | *{
30 | box-sizing: border-box;
31 | }
32 |
33 | html, body {
34 | margin: 0;
35 | font-family: sans-serif;
36 | font-size: 112.5%;
37 | }
38 |
39 | `;
40 |
--------------------------------------------------------------------------------
/client/src/common/Navigation.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { NavLink } from "react-router-dom";
3 | import styled from "styled-components/macro";
4 |
5 | export default function Navigation() {
6 | return (
7 |
12 | );
13 | }
14 |
15 | const Nav = styled.nav`
16 | padding: var(--size-m);
17 | background: var(--blue-main);
18 | display: flex;
19 |
20 | a {
21 | color: var(--blue-50);
22 | text-decoration: none;
23 |
24 | &.active {
25 | color: var(--orange-main);
26 | }
27 | }
28 |
29 | a + a {
30 | margin-left: var(--size-m);
31 | }
32 |
33 | a:last-child {
34 | margin-left: auto;
35 | }
36 | `;
37 |
--------------------------------------------------------------------------------
/client/src/common/Page.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import PropTypes from "prop-types";
3 | import styled from "styled-components/macro";
4 | import Navigation from "./Navigation";
5 |
6 | Page.propTypes = {
7 | children: PropTypes.node,
8 | };
9 |
10 | export default function Page({ children }) {
11 | return (
12 |
13 |
16 |
17 | {children}
18 |
19 | );
20 | }
21 |
22 | const Wrapper = styled.section`
23 | height: 100vh;
24 | display: grid;
25 | grid-template-rows: min-content min-content 1fr;
26 | background: var(--blue-75);
27 | color: white;
28 |
29 | > header {
30 | background: var(--blue-main);
31 | padding: var(--size-m);
32 |
33 | h1 {
34 | margin: 0;
35 | color: var(--orange-main);
36 | }
37 | }
38 |
39 | > main {
40 | display: grid;
41 | grid-auto-rows: min-content;
42 | align-items: start;
43 | justify-content: start;
44 | background: var(--blue-75);
45 | color: white;
46 | padding: var(--size-m);
47 | overflow-y: scroll;
48 | }
49 | `;
50 |
--------------------------------------------------------------------------------
/client/src/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom";
3 | import App from "./App";
4 | import * as serviceWorker from "./serviceWorker";
5 |
6 | ReactDOM.render(
7 |
8 |
9 | ,
10 | document.getElementById("root")
11 | );
12 |
13 | // If you want your app to work offline and load faster, you can change
14 | // unregister() to register() below. Note this comes with some pitfalls.
15 | // Learn more about service workers: https://bit.ly/CRA-PWA
16 | serviceWorker.unregister();
17 |
--------------------------------------------------------------------------------
/client/src/pages/Home.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import styled from "styled-components/macro";
3 | import Page from "../common/Page";
4 |
5 | export default function Home() {
6 | return (
7 |
8 | Resources
9 |
10 |
11 | RFC Specs (very dry but precise)
12 |
13 |
14 |
19 | The OAuth 2.0 Authorization Framework
20 |
21 |
26 | JSON Web Token (JWT)
27 |
28 |
29 |
30 | GitHub
31 |
32 |
37 | Creating OAuth Apps
38 |
39 |
44 | Webflow for OAuth Apps
45 |
46 |
47 |
48 | JWT.io
49 |
50 |
55 | Introduction to JSON Web Tokens
56 |
57 |
62 | Debugger
63 |
64 |
65 |
66 | );
67 | }
68 |
69 | const ReadingList = styled.section`
70 | display: grid;
71 | grid-gap: var(--size-s);
72 | `;
73 |
--------------------------------------------------------------------------------
/client/src/pages/Login.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import styled from "styled-components/macro";
3 | import Page from "../common/Page";
4 |
5 | export default function Login() {
6 | return (
7 |
8 |
9 | Login with GitHub
10 |
11 |
12 | );
13 | }
14 |
15 | const LoginWithGitHub = styled.a`
16 | text-decoration: none;
17 | color: var(--blue-main);
18 | padding: var(--size-m);
19 | border: 2px solid var(--blue-main);
20 | border-radius: var(--size-m);
21 |
22 | &::visited {
23 | text-decoration: none;
24 | color: var(--main-blue);
25 | }
26 | `;
27 |
--------------------------------------------------------------------------------
/client/src/pages/Profile.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import Page from "../common/Page";
3 |
4 | export default function Profile() {
5 | return ;
6 | }
7 |
--------------------------------------------------------------------------------
/client/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 |
--------------------------------------------------------------------------------
/client/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 |
--------------------------------------------------------------------------------
/nodemon.json:
--------------------------------------------------------------------------------
1 | {
2 | "ignore": ["client/*"]
3 | }
4 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "oauth-demo",
3 | "private": true,
4 | "version": "1.0.0",
5 | "description": "OAuth demo",
6 | "main": "server.js",
7 | "scripts": {
8 | "postinstall": "cd client && npm install",
9 | "test:watch": "cd client && npm run test:watch",
10 | "test": "npm run lint && npm run prettier && cd client && npm test",
11 | "lint": "eslint . --ext .js",
12 | "prettify": "prettier --write .",
13 | "dev": "concurrently \"npm run server\" \"npm run client\"",
14 | "client": "cd client && npm start",
15 | "prettier": "prettier --check \"**/*.{js,jsx,ts,tsx,md,mdx,html,css,json}\"",
16 | "server": "nodemon server.js",
17 | "start": "node server.js"
18 | },
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/jamarob/oauth-demo.git"
22 | },
23 | "keywords": [],
24 | "author": "Leon Machens",
25 | "license": "MIT",
26 | "bugs": {
27 | "url": "https://github.com/jamarob/oauth-demo/issues"
28 | },
29 | "homepage": "https://github.com/jamarob/oauth-demo#readme",
30 | "dependencies": {
31 | "express": "^4.17.1"
32 | },
33 | "devDependencies": {
34 | "@typescript-eslint/eslint-plugin": "^4.8.2",
35 | "@typescript-eslint/parser": "^4.8.2",
36 | "babel-eslint": "^10.1.0",
37 | "concurrently": "^5.3.0",
38 | "eslint": "^7.14.0",
39 | "eslint-config-prettier": "^6.15.0",
40 | "eslint-config-react-app": "^6.0.0",
41 | "eslint-plugin-flowtype": "^5.2.0",
42 | "eslint-plugin-import": "^2.22.1",
43 | "eslint-plugin-jsx-a11y": "^6.4.1",
44 | "eslint-plugin-react": "^7.21.5",
45 | "eslint-plugin-react-hooks": "^4.2.0",
46 | "husky": "^4.3.0",
47 | "lint-staged": "^10.5.2",
48 | "nodemon": "^2.0.6",
49 | "prettier": "2.2.0",
50 | "typescript": "^4.1.2"
51 | },
52 | "husky": {
53 | "hooks": {
54 | "pre-commit": "lint-staged",
55 | "pre-push": "npm test"
56 | }
57 | },
58 | "lint-staged": {
59 | "*.js": "eslint --cache --fix",
60 | "*.{js,css,md}": "prettier --write"
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 |
3 | const app = express();
4 | const port = process.env.PORT || 3001;
5 |
6 | app.listen(port, () => {
7 | console.log(`Server listening at http://localhost:${port}`);
8 | });
9 |
--------------------------------------------------------------------------------