From b82bd3fc3f766648aa7ad4498e5da05bcd2057eb Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 20 Dec 2024 17:43:36 +0100 Subject: [PATCH] Add discord client secret --- module.nix | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/module.nix b/module.nix index 0030fdf..d76a33c 100644 --- a/module.nix +++ b/module.nix @@ -26,6 +26,7 @@ in homeserverName = mkStringOption "The name of the homeserver to connect to." "localhost"; namespace = mkStringOption "The prefix to use for the MXIDs/aliases of bridged users/rooms. Should end with a _!" "_ooye_"; discordTokenPath = mkStringOption "The path to the discord token file." "/etc/ooye-discord-token"; + discordClientSecretPath = mkStringOption "The path to the discord token file." "/etc/ooye-discord-client-secret"; socket = mkStringOption "The socket to listen on, can either be a port number or a unix socket path." "6693"; bridgeOrigin = mkStringOption "The web frontend URL for the bridge, defaults to http://localhost:{socket}" ""; @@ -87,24 +88,35 @@ in AS_TOKEN=$(${lib.getExe pkgs.jq} -r .as_token ''${REGISTRATION_FILE}) HS_TOKEN=$(${lib.getExe pkgs.jq} -r .hs_token ''${REGISTRATION_FILE}) DISCORD_TOKEN=$(cat /run/credentials/matrix-ooye-pre-start.service/discord_token) + DISCORD_CLIENT_SECRET=$(cat /run/credentials/matrix-ooye-pre-start.service/discord_client_secret) + # Check if we have all required tokens if [[ -z "$AS_TOKEN" || "$AS_TOKEN" == "null" ]]; then AS_TOKEN=$(${lib.getExe pkgs.openssl} rand -hex 64) echo "Generated new AS token: ''${AS_TOKEN}" fi + if [[ -z "$HS_TOKEN" || "$HS_TOKEN" == "null" ]]; then HS_TOKEN=$(${lib.getExe pkgs.openssl} rand -hex 64) echo "Generated new HS token: ''${HS_TOKEN}" fi + if [[ -z "$DISCORD_TOKEN" ]]; then echo "No Discord token found at '${cfg.discordTokenPath}'" + echo "You can find this on the 'Bot' tab of your Discord application." + exit 1 + fi + + if [[ -z "$DISCORD_CLIENT_SECRET" ]]; then + echo "No Discord client secret found at '${cfg.discordTokenPath}'" + echo "You can find this on the 'OAuth2' tab of your Discord application." exit 1 fi shred -u ''${REGISTRATION_FILE} cp --no-preserve=mode,ownership ${baseConfig} ''${REGISTRATION_FILE} - ${lib.getExe pkgs.jq} '.as_token = "'$AS_TOKEN'" | .hs_token = "'$HS_TOKEN'" | .ooye.discord_token = "'$DISCORD_TOKEN'"' ''${REGISTRATION_FILE} > ''${REGISTRATION_FILE}.tmp + ${lib.getExe pkgs.jq} '.as_token = "'$AS_TOKEN'" | .hs_token = "'$HS_TOKEN'" | .ooye.discord_token = "'$DISCORD_TOKEN'" | .ooye.discord_client_secret = "'$DISCORD_CLIENT_SECRET'"' ''${REGISTRATION_FILE} > ''${REGISTRATION_FILE}.tmp shred -u ''${REGISTRATION_FILE} mv ''${REGISTRATION_FILE}.tmp ''${REGISTRATION_FILE} @@ -134,6 +146,7 @@ in LoadCredential = [ "discord_token:${cfg.discordTokenPath}" + "discord_client_secret:${cfg.discordClientSecretPath}" ]; }; };