Use access tokens instead of userand password

This commit is contained in:
Jorge Alberto Díaz Orozco (Akiel)
2026-03-23 22:57:43 +01:00
parent d9187e3d33
commit c551865cfd
4 changed files with 23 additions and 52 deletions
+2 -30
View File
@@ -7,28 +7,11 @@ BOLD='\033[1m'
RESET='\033[0m'
SERVER="${INPUT_SERVER}"
USER="${INPUT_USER}"
PASSWORD="${INPUT_PASSWORD}"
AUTH_TOKEN="${INPUT_AUTH_TOKEN}"
USER_ID="${INPUT_USER_ID}"
MESSAGE="${INPUT_MESSAGE}"
CHANNEL="${INPUT_CHANNEL}"
LOGIN_RESPONSE=$(curl -s -X POST \
-H "Content-Type: application/json" \
-d "$(jq -n --arg user "$USER" --arg password "$PASSWORD" '{"user": $user, "password": $password}')" \
"${SERVER}/api/v1/login")
mapfile -t login_data < <(jq -r '.data.authToken, .data.userId' <<< "$LOGIN_RESPONSE")
AUTH_TOKEN="${login_data[0]}"
USER_ID="${login_data[1]}"
if [ -z "$AUTH_TOKEN" ] || [ "$AUTH_TOKEN" = "null" ]; then
LOGIN_ERROR=$(jq -r '.message // "unknown error"' <<< "$LOGIN_RESPONSE")
echo -e "${RED}${BOLD}✗ Login failed${RESET} — ${LOGIN_ERROR}"
exit 1
fi
echo -e "${GREEN}✓ Logged in${RESET} — ${USER}@${SERVER}"
RESPONSE=$(curl -s -X POST \
-H "Content-Type: application/json" \
-H "X-Auth-Token: ${AUTH_TOKEN}" \
@@ -49,14 +32,3 @@ if [ "$SUCCESS" != "true" ]; then
fi
echo -e "${GREEN}${BOLD}✓ Message sent${RESET} — channel: ${BOLD}${CHANNEL_NAME}${RESET}, sender: ${SENDER}, id: ${MSG_ID}"
LOGOUT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
-H "X-Auth-Token: ${AUTH_TOKEN}" \
-H "X-User-Id: ${USER_ID}" \
"${SERVER}/api/v1/logout") || true
if [ "${LOGOUT_STATUS}" = "200" ]; then
echo -e "${GREEN}✓ Logged out${RESET}"
else
echo -e "${RED}✗ Logout failed${RESET} — HTTP ${LOGOUT_STATUS}"
fi