Add discord client secret
This commit is contained in:
parent
282506c547
commit
b82bd3fc3f
1 changed files with 14 additions and 1 deletions
15
module.nix
15
module.nix
|
@ -26,6 +26,7 @@ in
|
||||||
homeserverName = mkStringOption "The name of the homeserver to connect to." "localhost";
|
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_";
|
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";
|
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";
|
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}" "";
|
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})
|
AS_TOKEN=$(${lib.getExe pkgs.jq} -r .as_token ''${REGISTRATION_FILE})
|
||||||
HS_TOKEN=$(${lib.getExe pkgs.jq} -r .hs_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_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
|
if [[ -z "$AS_TOKEN" || "$AS_TOKEN" == "null" ]]; then
|
||||||
AS_TOKEN=$(${lib.getExe pkgs.openssl} rand -hex 64)
|
AS_TOKEN=$(${lib.getExe pkgs.openssl} rand -hex 64)
|
||||||
echo "Generated new AS token: ''${AS_TOKEN}"
|
echo "Generated new AS token: ''${AS_TOKEN}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$HS_TOKEN" || "$HS_TOKEN" == "null" ]]; then
|
if [[ -z "$HS_TOKEN" || "$HS_TOKEN" == "null" ]]; then
|
||||||
HS_TOKEN=$(${lib.getExe pkgs.openssl} rand -hex 64)
|
HS_TOKEN=$(${lib.getExe pkgs.openssl} rand -hex 64)
|
||||||
echo "Generated new HS token: ''${HS_TOKEN}"
|
echo "Generated new HS token: ''${HS_TOKEN}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$DISCORD_TOKEN" ]]; then
|
if [[ -z "$DISCORD_TOKEN" ]]; then
|
||||||
echo "No Discord token found at '${cfg.discordTokenPath}'"
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
shred -u ''${REGISTRATION_FILE}
|
shred -u ''${REGISTRATION_FILE}
|
||||||
cp --no-preserve=mode,ownership ${baseConfig} ''${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}
|
shred -u ''${REGISTRATION_FILE}
|
||||||
mv ''${REGISTRATION_FILE}.tmp ''${REGISTRATION_FILE}
|
mv ''${REGISTRATION_FILE}.tmp ''${REGISTRATION_FILE}
|
||||||
|
@ -134,6 +146,7 @@ in
|
||||||
|
|
||||||
LoadCredential = [
|
LoadCredential = [
|
||||||
"discord_token:${cfg.discordTokenPath}"
|
"discord_token:${cfg.discordTokenPath}"
|
||||||
|
"discord_client_secret:${cfg.discordClientSecretPath}"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue