Mojito Auth
NodeJS authentication server for remote loading and IP restricting fivem resources. Using Express JS for the REST API and Discord.js for logging and whitelisting.
Usage
The usage has been simplified in the v2 update, only adding new files to the system needs to be done manually. For this example I will use a resources called "mojito_auth".
First add an empty array to the database.json as follows
Code:
{
"mojito_auth-server": []
}
Then, place your file in the ./scripts directory i.e. ./scripts/mojito_auth-server.lua
Note that this file can be obfuscated or left in source code form
To access within a script you need to use a HTTP request as follows:
Code:
-- Perform request to IP and port of the auth server with the resource name as a query
PerformHttpRequest("http://127.0.0.1:3000/?script=mojito_auth-server"), function(err, data, headers)
if data then
-- if data is returned we run the code
local loading = load or loadstring
loading(data)()
else
-- if the user is not authorised the code is not sent and you can print a message or do whatever
print("YOU ARE NOT AUTHORISED TO USE THIS SCRIPT")
end
end, "GET")
If you wish to remote load a client file you can use a callback or some event handlers
Code:
-- client
TriggerCallback("grab-code", function(data)
local loading = load or loadstring
loading(data)()
end)
-- server
CreateCallback("grab-code", function(source, cb)
PerformHttpRequest("http://127.0.0.1:3000/?script=mojito_auth-server"), function(err, data, headers)
if data then
cb(data)
end
end, "GET")
end)
To whitelist an IP address for a script, create a .env file containing your discord bot token and prefix i.e.
Code:
TOKEN= [BOT Token]
CLIENT_ID= [Bot's Client ID]
GUILD_ID= [Discord Guild / Server ID]
WEBHOOK= [Full Webhook URL]
PERMISSION_ROLE= [ID of the Required Role]
Use the command /authorise and follow the prompts to whitelist an IP for a product
and /deauthorise to remove an IP address from the whitelist for a script
Webhook Logging:
v2.0 update:
- Refactor to discord.js v13
- Fixed issue with unauthorised players recieving false as a string
- Code Cleanup and Easier Useage