diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 1164b45..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Publish Docker image -on: - release: - types: [ published ] - push: - tags: - - v1.* -jobs: - push_to_registry: - name: Push Docker Image to Docker Hub - runs-on: ubuntu-latest - steps: - - name: Check Out The Repo - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Get Smart Tag - id: prepare - uses: Surgo/docker-smart-tag-action@v1 - with: - docker_image: krgamestudios/auth-server - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Push to Docker Hub - uses: docker/build-push-action@v2 - with: - push: true - tags: ${{ steps.prepare.outputs.tag }} - platforms: amd64,arm diff --git a/LICENSE b/LICENSE deleted file mode 100644 index be733db..0000000 --- a/LICENSE +++ /dev/null @@ -1,11 +0,0 @@ -Copyright (c) 2021 Kayne Ruse, KR Game Studios - -This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source distribution. diff --git a/configure-script.js b/configure-script.js deleted file mode 100644 index 2f5ba25..0000000 --- a/configure-script.js +++ /dev/null @@ -1,152 +0,0 @@ -//setup -const readline = require('readline'); -const fs = require('fs'); -const crypto = require("crypto"); - -const uuid = (bytes = 16) => crypto.randomBytes(bytes).toString("hex"); - -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - terminal: false -}); - -//manually promisify this (util didn't work) -const question = (prompt, def = null) => { - return new Promise((resolve, reject) => { - rl.question(`${prompt}${def ? ` (${def})` : ''}: `, answer => { - //loop on required - if (def === null && !answer) { - return resolve(question(prompt, def)); - } - - return resolve(answer || def); - }); - }); -}; - -//questions -(async () => { - //project configuration - const appName = await question('App Name', 'auth'); - const appWebAddress = await question('Web Addr', `${appName}.example.com`); - const appPort = await question('App Port', '3200'); - - const appDBUser = await question('DB User', appName); - const appDBPass = await question('DB Pass', uuid()); - const dbRootPass = await question('DB Root Pass'); - - const appMailSMTP = await question('Mail SMTP', 'smtp.example.com'); - const appMailUser = await question('Mail User', 'example@example.com'); - const appMailPass = await question('Mail Pass'); - const appMailPhysical = await question('Mail Physical'); - - const appDefaultUser = await question('App Default User', ''); - const appDefaultPass = await question('App Default Pass', ''); - - const appSecretAccess = await question('Access Token Secret', uuid(32)); - const appSecretRefresh = await question('Refresh Token Secret', uuid(32)); - - const supportEmail = await question('Support Email', appMailUser); - - //generate the files - const ymlfile = ` -version: '3' - -services: - ${appName}: - build: - context: . - ports: - - "${appPort}" - labels: - - "traefik.enable=true" - - "traefik.http.routers.${appName}router.rule=Host(\`${appWebAddress}\`)" - - "traefik.http.routers.${appName}router.entrypoints=websecure" - - "traefik.http.routers.${appName}router.tls.certresolver=myresolver" - - "traefik.http.routers.${appName}router.service=${appName}service@docker" - - "traefik.http.services.${appName}service.loadbalancer.server.port=${appPort}" - environment: - - WEB_PROTOCOL=https - - WEB_ADDRESS=${appWebAddress} - - WEB_PORT=${appPort} - - DB_HOSTNAME=database - - DB_DATABASE=${appName} - - DB_USERNAME=${appDBUser} - - DB_PASSWORD=${appDBPass} - - DB_TIMEZONE=Australia/Sydney - - MAIL_SMTP=${appMailSMTP} - - MAIL_USERNAME=${appMailUser} - - MAIL_PASSWORD=${appMailPass} - - MAIL_PHYSICAL=${appMailPhysical} - - ADMIN_DEFAULT_USERNAME=${appDefaultUser} - - ADMIN_DEFAULT_PASSWORD=${appDefaultPass} - - SECRET_ACCESS=${appSecretAccess} - - SECRET_REFRESH=${appSecretRefresh} - networks: - - app-network - depends_on: - - database - database: - image: mariadb:latest - environment: - MYSQL_DATABASE: ${appName} - MYSQL_USER: ${appDBUser} - MYSQL_PASSWORD: ${appDBPass} - MYSQL_ROOT_PASSWORD: ${dbRootPass} - networks: - - app-network - volumes: - - ./mysql:/var/lib/mysql - - ./startup.sql:/docker-entrypoint-initdb.d/startup.sql:ro - traefik_${appName}: - container_name: ${appName}_traefik - image: "traefik:v2.4" - container_name: "traefik" - command: - - "--log.level=ERROR" - - "--api.insecure=false" - - "--providers.docker=true" - - "--providers.docker.exposedbydefault=false" - - "--entrypoints.websecure.address=:443" - - "--certificatesresolvers.myresolver.acme.tlschallenge=true" - - "--certificatesresolvers.myresolver.acme.email=${supportEmail}" - - "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json" - ports: - - "80:80" - - "443:443" - volumes: - - "./letsencrypt:/letsencrypt" - - "/var/run/docker.sock:/var/run/docker.sock:ro" - networks: - - app-network -networks: - app-network: - driver: bridge -`; - -const dockerfile = ` -FROM node:15 -WORKDIR "/app" -COPY package*.json ./ -COPY . /app -RUN npm install --production -EXPOSE ${appPort} -USER node -ENTRYPOINT ["bash", "-c"] -CMD ["sleep 10 && npm start"] -`; - - const sqlfile = ` -CREATE DATABASE IF NOT EXISTS ${appName}; -CREATE USER IF NOT EXISTS '${appDBUser}'@'%' IDENTIFIED BY '${appDBPass}'; -GRANT ALL PRIVILEGES ON ${appName}.* TO '${appDBUser}'@'%'; -`; - - fs.writeFileSync('docker-compose.yml', ymlfile); - fs.writeFileSync('Dockerfile', dockerfile); - fs.writeFileSync('startup.sql', sqlfile); -})() - .then(() => rl.close()) - .catch(e => console.error(e)) -; diff --git a/package-lock.json b/package-lock.json index 3eca186..d3ac35b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,11 +5,11 @@ "requires": true, "packages": { "": { + "name": "auth-server", "version": "1.0.0", "license": "ISC", "dependencies": { "bcryptjs": "^2.4.3", - "body-parser": "^1.19.0", "cors": "^2.8.5", "dotenv": "^8.2.0", "express": "^4.17.1", diff --git a/package.json b/package.json index 9451ae6..bd26122 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "homepage": "https://github.com/krgamestudios/auth-server#readme", "dependencies": { "bcryptjs": "^2.4.3", - "body-parser": "^1.19.0", "cors": "^2.8.5", "dotenv": "^8.2.0", "express": "^4.17.1", diff --git a/server/server.js b/server/server.js index fbd5186..254b9f7 100644 --- a/server/server.js +++ b/server/server.js @@ -5,11 +5,10 @@ require('dotenv').config(); const express = require('express'); const app = express(); const server = require('http').Server(app); -const bodyParser = require('body-parser'); const cors = require('cors'); //config -app.use(bodyParser.json()); +app.use(express.json()); app.use(cors()); //database connection diff --git a/test/debug-startup.sql b/test/debug-startup.sql deleted file mode 100644 index f4624fa..0000000 --- a/test/debug-startup.sql +++ /dev/null @@ -1,4 +0,0 @@ -#use this while debugging -CREATE DATABASE IF NOT EXISTS auth; -CREATE USER IF NOT EXISTS 'auth'@'%' IDENTIFIED BY 'venusaur'; -GRANT ALL PRIVILEGES ON auth.* TO 'auth'@'%'; diff --git a/test/dev-auth-requests.rest b/test/dev-auth-requests.rest deleted file mode 100644 index 5b6d17e..0000000 --- a/test/dev-auth-requests.rest +++ /dev/null @@ -1,68 +0,0 @@ -#Signup -POST https://dev-auth.eggtrainer.com/auth/signup HTTP/1.1 -Content-Type: application/json - -{ - "email": "kayneruse@gmail.com", - "username": "Ratstail91", - "password": "helloworld" -} - -### - -#Login -POST https://dev-auth.eggtrainer.com/auth/login HTTP/1.1 -Content-Type: application/json - -{ - "email": "kayneruse@gmail.com", - "password": "helloworld" -} - -### - -#Query data -GET https://dev-auth.eggtrainer.com/auth/account HTTP/1.1 -Authorization: Bearer - -### - -#Logout -DELETE https://dev-auth.eggtrainer.com/auth/logout HTTP/1.1 -Authorization: Bearer - -{ - "token": "" -} - -### - -#Refresh -POST https://dev-auth.eggtrainer.com/auth/token HTTP/1.1 -Content-Type: application/json - -{ - "token": "" -} - -### - -#Update account data -PATCH https://dev-auth.eggtrainer.com/auth/update HTTP/1.1 -Content-Type: application/json -Authorization: Bearer - -{ - "contact": "true" -} - -### - -#Delete account -DELETE https://dev-auth.eggtrainer.com/auth/deletion HTTP/1.1 -Authorization: Bearer -Content-Type: application/json - -{ - "password": "helloworld" -} diff --git a/test/requests.rest b/test/requests.rest deleted file mode 100644 index f8076e8..0000000 --- a/test/requests.rest +++ /dev/null @@ -1,68 +0,0 @@ -#Signup -POST http://127.0.0.1:3200/auth/signup HTTP/1.1 -Content-Type: application/json - -{ - "email": "kayneruse@gmail.com", - "username": "Ratstail91", - "password": "helloworld" -} - -### - -#Login -POST http://127.0.0.1:3200/auth/login HTTP/1.1 -Content-Type: application/json - -{ - "email": "kayneruse@gmail.com", - "password": "helloworld" -} - -### - -#Query data -GET http://127.0.0.1:3200/auth/account HTTP/1.1 -Authorization: Bearer - -### - -#Logout -DELETE http://127.0.0.1:3200/auth/logout HTTP/1.1 -Authorization: Bearer - -{ - "token": "" -} - -### - -#Refresh -POST http://127.0.0.1:3200/auth/token HTTP/1.1 -Content-Type: application/json - -{ - "token": "" -} - -### - -#Update account data -PATCH http://127.0.0.1:3200/auth/update HTTP/1.1 -Content-Type: application/json -Authorization: Bearer - -{ - "contact": "true" -} - -### - -#Delete account -DELETE http://127.0.0.1:3200/auth/deletion HTTP/1.1 -Authorization: Bearer -Content-Type: application/json - -{ - "password": "helloworld" -}