From d2c505b1674b521091c624ee8ad04655608731b9 Mon Sep 17 00:00:00 2001 From: Christof <bauer.christof@gmail.com> Date: Wed, 8 Nov 2023 16:32:59 +0100 Subject: [PATCH] [WIP] Create-Matrix-Admin-Script --- .gitignore | 2 ++ create-matrix-admin.sh | 31 +++++++++++++++++++++++++++++++ src/config.ts | 3 +++ 3 files changed, 36 insertions(+) create mode 100755 create-matrix-admin.sh diff --git a/.gitignore b/.gitignore index 69de592..7846028 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,7 @@ node_modules terraform/.holi-terraform.key dist .envrc.local +.env +.env.local coverage/ *.zip diff --git a/create-matrix-admin.sh b/create-matrix-admin.sh new file mode 100755 index 0000000..72e63c6 --- /dev/null +++ b/create-matrix-admin.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# This file contains shell commands that are needed to create an admin for Matrix Chat +# which is needed to set up a working local dev environment for this project. + +URL="http://127.0.0.1:8008/_synapse/admin/v1/register" +username="admin" +password="admin" +admin=true +secret=MATRIX_ADMIN_SECRET + +# 1. Get Nonce +response=$(curl -s $URL) +nonce=$(jq -r ".nonce" <<<"$response") +echo "Nonce: $nonce" + +# 2. Generate HMAC +hmac=$( + echo "$nonce" "$username" "$password" "$admin" | + openssl sha1 -hmac "$secret" | + awk '{print $2}' +) +echo "HMAC: $hmac" + +# 2. Create Matrix Admin +res=$( + curl -s $URL -X POST \ + -H "Content-Type: application/json" \ + -d "{ \"nonce\": \"$nonce\", \"username\": \"$username\", \"password\": \"$password\", \"admin\": \"$admin\", \"mac\": \"$hmac\" }" +) +echo $res diff --git a/src/config.ts b/src/config.ts index 6483eed..d972408 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,3 +3,6 @@ export const ENVIRONMENT = process.env.ENVIRONMENT // The issuer URL for the OpenID Connect provider used by the chat instance. export const CHAT_OIDC_ISSUER = process.env.CHAT_OIDC_ISSUER + +// The secret for generating the hmac hash to register a Matrix admin user. +export const MATRIX_ADMIN_SECRET = process.env.MATRIX_ADMIN_SECRET -- GitLab