Compare commits

..

4 Commits

Author SHA1 Message Date
Kayne Ruse cc6b7bd7b4 Fixed an import/require problem 2021-12-11 10:11:56 +00:00
Kayne Ruse 9bdf3925a3 Implemented a post-validation hook 2021-12-11 09:59:57 +00:00
Kayne Ruse a299bab794 Preparing for Egg Trainer merge 2021-11-18 14:59:30 +00:00
Kayne Ruse 8460d03181 Updated package-lock.json 2021-11-17 06:14:08 +00:00
7 changed files with 88 additions and 9 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ jobs:
docker_image: krgamestudios/auth-server docker_image: krgamestudios/auth-server
- name: Login to DockerHub - name: Login to DockerHub
uses: docker/login-action@v1 uses: docker/login-action@v1
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
+2
View File
@@ -26,6 +26,8 @@ Content-Type: application/json
//DOCS: Used for validating the email address specified above //DOCS: Used for validating the email address specified above
GET /auth/validation?username=example&token=12345678 GET /auth/validation?username=example&token=12345678
//DOCS: If the environment variable HOOK_POST_VALIDATION is set to a URL, then the server will send a GET message to that URL with the newly created account's index
GET https://{HOOK_POST_VALIDATION}?accountIndex={index}
### ###
+4 -2
View File
@@ -30,6 +30,7 @@ const question = (prompt, def = null) => {
//project configuration //project configuration
const appName = await question('App Name', 'auth'); const appName = await question('App Name', 'auth');
const appWebAddress = await question('Web Addr', `${appName}.example.com`); const appWebAddress = await question('Web Addr', `${appName}.example.com`);
const postValidationHook = await question('Post Validation Hook', '');
const resetAddress = await question('Reset Addr', `example.com/reset`); const resetAddress = await question('Reset Addr', `example.com/reset`);
const appPort = await question('App Port', '3200'); const appPort = await question('App Port', '3200');
@@ -70,6 +71,7 @@ services:
environment: environment:
- WEB_PROTOCOL=https - WEB_PROTOCOL=https
- WEB_ADDRESS=${appWebAddress} - WEB_ADDRESS=${appWebAddress}
- HOOK_POST_VALIDATION=${postValidationHook}
- WEB_RESET_ADDRESS=${resetAddress} - WEB_RESET_ADDRESS=${resetAddress}
- WEB_PORT=${appPort} - WEB_PORT=${appPort}
- DB_HOSTNAME=database - DB_HOSTNAME=database
@@ -85,7 +87,7 @@ services:
- ADMIN_DEFAULT_PASSWORD=${appDefaultPass} - ADMIN_DEFAULT_PASSWORD=${appDefaultPass}
- SECRET_ACCESS=${appSecretAccess} - SECRET_ACCESS=${appSecretAccess}
- SECRET_REFRESH=${appSecretRefresh} - SECRET_REFRESH=${appSecretRefresh}
networks: networks:
- app-network - app-network
depends_on: depends_on:
- database - database
@@ -96,7 +98,7 @@ services:
MYSQL_USER: ${appDBUser} MYSQL_USER: ${appDBUser}
MYSQL_PASSWORD: ${appDBPass} MYSQL_PASSWORD: ${appDBPass}
MYSQL_ROOT_PASSWORD: ${dbRootPass} MYSQL_ROOT_PASSWORD: ${dbRootPass}
networks: networks:
- app-network - app-network
volumes: volumes:
- ./mysql:/var/lib/mysql - ./mysql:/var/lib/mysql
+60 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "auth-server", "name": "auth-server",
"version": "1.4.3", "version": "1.4.7",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "auth-server", "name": "auth-server",
"version": "1.4.3", "version": "1.4.7",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
@@ -16,6 +16,7 @@
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"mariadb": "^2.5.4", "mariadb": "^2.5.4",
"node-cron": "^2.0.3", "node-cron": "^2.0.3",
"node-fetch": "^2.6.6",
"nodemailer": "^6.6.3", "nodemailer": "^6.6.3",
"sequelize": "^6.6.5" "sequelize": "^6.6.5"
}, },
@@ -1280,6 +1281,17 @@
"node": ">=6.0.0" "node": ">=6.0.0"
} }
}, },
"node_modules/node-fetch": {
"version": "2.6.6",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz",
"integrity": "sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==",
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
}
},
"node_modules/nodemailer": { "node_modules/nodemailer": {
"version": "6.6.3", "version": "6.6.3",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.3.tgz", "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.3.tgz",
@@ -1910,6 +1922,11 @@
"nodetouch": "bin/nodetouch.js" "nodetouch": "bin/nodetouch.js"
} }
}, },
"node_modules/tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o="
},
"node_modules/type-fest": { "node_modules/type-fest": {
"version": "0.8.1", "version": "0.8.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz",
@@ -2045,6 +2062,20 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
"integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE="
},
"node_modules/whatwg-url": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
"integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=",
"dependencies": {
"tr46": "~0.0.3",
"webidl-conversions": "^3.0.0"
}
},
"node_modules/widest-line": { "node_modules/widest-line": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/widest-line/-/widest-line-3.1.0.tgz", "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-3.1.0.tgz",
@@ -3092,6 +3123,14 @@
"tz-offset": "0.0.1" "tz-offset": "0.0.1"
} }
}, },
"node-fetch": {
"version": "2.6.6",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz",
"integrity": "sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==",
"requires": {
"whatwg-url": "^5.0.0"
}
},
"nodemailer": { "nodemailer": {
"version": "6.6.3", "version": "6.6.3",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.3.tgz", "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.3.tgz",
@@ -3561,6 +3600,11 @@
"nopt": "~1.0.10" "nopt": "~1.0.10"
} }
}, },
"tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o="
},
"type-fest": { "type-fest": {
"version": "0.8.1", "version": "0.8.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz",
@@ -3663,6 +3707,20 @@
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
}, },
"webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
"integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE="
},
"whatwg-url": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
"integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=",
"requires": {
"tr46": "~0.0.3",
"webidl-conversions": "^3.0.0"
}
},
"widest-line": { "widest-line": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/widest-line/-/widest-line-3.1.0.tgz", "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-3.1.0.tgz",
+2 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "auth-server", "name": "auth-server",
"version": "1.4.4", "version": "1.4.7",
"description": "An API centric auth server. Uses Sequelize and mariaDB by default.", "description": "An API centric auth server. Uses Sequelize and mariaDB by default.",
"main": "server/server.js", "main": "server/server.js",
"scripts": { "scripts": {
@@ -26,6 +26,7 @@
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"mariadb": "^2.5.4", "mariadb": "^2.5.4",
"node-cron": "^2.0.3", "node-cron": "^2.0.3",
"node-fetch": "^2.6.6",
"nodemailer": "^6.6.3", "nodemailer": "^6.6.3",
"sequelize": "^6.6.5" "sequelize": "^6.6.5"
}, },
+17 -1
View File
@@ -1,4 +1,5 @@
const { pendingSignups, accounts } = require('../database/models'); const { pendingSignups, accounts } = require('../database/models');
const fetch = require('node-fetch');
//auth/validation //auth/validation
const route = async (req, res) => { const route = async (req, res) => {
@@ -19,7 +20,7 @@ const route = async (req, res) => {
} }
//move data to the accounts table //move data to the accounts table
accounts.create({ const [account] = await accounts.upsert({
email: info.email, email: info.email,
username: info.username, username: info.username,
hash: info.hash, hash: info.hash,
@@ -35,6 +36,21 @@ const route = async (req, res) => {
//finally //finally
res.status(200).send('Validation succeeded!'); res.status(200).send('Validation succeeded!');
//post-validation hook
if (process.env.HOOK_POST_VALIDATION) {
const probe = await fetch(`https://${process.env.HOOK_POST_VALIDATION}?accountIndex=${account.index}`);
if (!probe.ok) {
console.error('Could not probe the post validation hook');
} else {
console.log('Validation hook probe successful'); //TODO: remove this
}
//discard the result
} else {
console.log('No validation hook'); //TODO: remove this
}
}; };
module.exports = route; module.exports = route;
+2 -2
View File
@@ -12,8 +12,8 @@ module.exports = (index, email, username, type, admin, mod) => {
mod, mod,
}; };
const accessToken = jwt.sign(content, process.env.SECRET_ACCESS, { expiresIn: '10m' }); const accessToken = jwt.sign(content, process.env.SECRET_ACCESS, { expiresIn: '10m', issuer: 'auth' });
const refreshToken = jwt.sign(content, process.env.SECRET_REFRESH, { expiresIn: '30d' }); const refreshToken = jwt.sign(content, process.env.SECRET_REFRESH, { expiresIn: '30d', issuer: 'auth' });
tokens.create({ token: refreshToken, email: email }); tokens.create({ token: refreshToken, email: email });