Skip to content

Commit

Permalink
fix(core): cfx.re login match by admin id (closes #571)
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Jan 17, 2023
1 parent b4ec48e commit 1d6a769
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 27 deletions.
16 changes: 0 additions & 16 deletions core/components/AdminVault/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export default class AdminVault {
}


//================================================================
/**
* sets the admins file refresh routine
*/
Expand All @@ -111,7 +110,6 @@ export default class AdminVault {
}


//================================================================
/**
* Creates a admins.json file based on the first account
* @param {string} username
Expand Down Expand Up @@ -159,7 +157,6 @@ export default class AdminVault {
}


//================================================================
/**
* Returns a list of admins and permissions
*/
Expand All @@ -176,7 +173,6 @@ export default class AdminVault {
}


//================================================================
/**
* Returns the raw array of admins, except for the hash
*/
Expand All @@ -186,7 +182,6 @@ export default class AdminVault {
}


//================================================================
/**
* Returns all data from an admin by provider user id (ex discord id), or false
* @param {string} uid
Expand All @@ -204,7 +199,6 @@ export default class AdminVault {
}


//================================================================
/**
* Returns all data from an admin by their name, or false
* @param {string} uname
Expand All @@ -220,7 +214,6 @@ export default class AdminVault {
}


//================================================================
/**
* Returns all data from an admin by game identifier, or false
* @param {string[]} identifiers
Expand All @@ -239,7 +232,6 @@ export default class AdminVault {
}


//================================================================
/**
* Returns a list with all registered permissions
*/
Expand All @@ -248,7 +240,6 @@ export default class AdminVault {
}


//================================================================
/**
* Writes to storage the admins file
*/
Expand All @@ -260,7 +251,6 @@ export default class AdminVault {
}


//================================================================
/**
* Writes to storage the admins file
*/
Expand Down Expand Up @@ -288,7 +278,6 @@ export default class AdminVault {
}


//================================================================
/**
* Add a new admin to the admins file
* NOTE: I'm fully aware this coud be optimized. Leaving this way to improve readability and error verbosity
Expand Down Expand Up @@ -345,7 +334,6 @@ export default class AdminVault {
}


//================================================================
/**
* Edit admin and save to the admins file
* @param {string} name
Expand Down Expand Up @@ -404,7 +392,6 @@ export default class AdminVault {
}


//================================================================
/**
* Refreshes admin's social login data
* @param {string} name
Expand Down Expand Up @@ -437,7 +424,6 @@ export default class AdminVault {
}


//================================================================
/**
* Delete admin and save to the admins file
* @param {string} name
Expand Down Expand Up @@ -467,7 +453,6 @@ export default class AdminVault {
}
}

//================================================================
/**
* Loads the admins.json file into the admins list
* NOTE: The verbosity here is driving me insane.
Expand Down Expand Up @@ -553,7 +538,6 @@ export default class AdminVault {
}


//================================================================
/**
* Notify game server about admin changes
*/
Expand Down
6 changes: 4 additions & 2 deletions core/components/AdminVault/providers/CitizenFX.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ export default class CitizenFXProvider {
*
* @param {object} tokenSet
* @param {object} userInfo
* @returns {(object)}
* @param {string} identifier
* @returns {object}
*/
async getUserSession(tokenSet, userInfo) {
async getUserSession(tokenSet, userInfo, identifier) {
return {
provider: 'citizenfx',
provider_uid: userInfo.name,
provider_identifier: identifier,
// expires_at: tokenSet.expires_at,
expires_at: Math.round(Date.now() / 1000) + 86400,
picture: userInfo.picture,
Expand Down
10 changes: 5 additions & 5 deletions core/components/WebServer/requestAuthenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ export const authLogic = (sess, perm, epType) => {
let admin = globals.adminVault.getAdminByName(sess.auth.username);
if (admin) {
if (
typeof sess.auth.password_hash == 'string'
&& admin.password_hash == sess.auth.password_hash
typeof sess.auth.password_hash === 'string'
&& admin.password_hash === sess.auth.password_hash
) {
isValidAuth = true;
} else if (
typeof sess.auth.provider == 'string'
&& typeof admin.providers[sess.auth.provider] == 'object'
&& sess.auth.provider_uid == admin.providers[sess.auth.provider].id
typeof sess.auth.provider === 'string'
&& typeof admin.providers[sess.auth.provider] === 'object'
&& sess.auth.provider_identifier === admin.providers[sess.auth.provider].identifier
) {
isValidAuth = true;
}
Expand Down
6 changes: 3 additions & 3 deletions core/webroutes/authentication/providerCallback.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const modulename = 'WebServer:ProviderCallback';
import crypto from 'node:crypto';
import logger from '@core/extras/console.js';
import logger, { ogConsole } from '@core/extras/console.js';
import { verbose } from '@core/globalData';
const { dir, log, logOk, logWarn, logError } = logger(modulename);

Expand Down Expand Up @@ -102,7 +102,7 @@ export default async function ProviderCallback(ctx) {

//Check & Login user
try {
const admin = globals.adminVault.getAdminByProviderUID(userInfo.name);
const admin = globals.adminVault.getAdminByIdentifiers([identifier]);
if (!admin) {
ctx.session.auth = {};
return returnJustMessage(
Expand All @@ -113,7 +113,7 @@ export default async function ProviderCallback(ctx) {
}

//Setting session
ctx.session.auth = await globals.adminVault.providers.citizenfx.getUserSession(tokenSet, userInfo);
ctx.session.auth = await globals.adminVault.providers.citizenfx.getUserSession(tokenSet, userInfo, identifier);
ctx.session.auth.username = admin.name;

//Save the updated provider identifier & data to the admins file
Expand Down
2 changes: 1 addition & 1 deletion docs/dev_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
- [x] set nui/vite.config.ts > target > chrome103
- [x] checkJoin: add messages to locale files
- [x] checkJoin: customMessage `\n` to `<br>`
- [ ] fix cfx.re login match by admin id
- [x] fix(core): cfx.re login match by admin id instead of name
- [ ] bot: change settings page description
- [ ] update readme with new features
- [ ] fix broken runtime stats
Expand Down

0 comments on commit 1d6a769

Please sign in to comment.