mirror of
https://github.com/BishopFox/otto-support.git
synced 2026-11-07 10:26:04 -10:00
28 lines
768 B
Bash
Executable File
28 lines
768 B
Bash
Executable File
#!/bin/bash
|
|
# Generate a signed session token for internal service access.
|
|
# Requires the SESSION_SIGNING_KEY from the runtime environment.
|
|
#
|
|
# Usage: ./scripts/mint-token.sh <signing_key> [user_id] [role]
|
|
|
|
SIGNING_KEY="${1:?Usage: mint-token.sh <signing_key> [user_id] [role]}"
|
|
USER_ID="${2:-support-agent}"
|
|
ROLE="${3:-support}"
|
|
|
|
SIGNER_URL="http://127.0.0.1:9003/sign"
|
|
|
|
RESPONSE=$(curl -s -X POST "$SIGNER_URL" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"signing_key\":\"$SIGNING_KEY\",\"user_id\":\"$USER_ID\",\"role\":\"$ROLE\"}")
|
|
|
|
if echo "$RESPONSE" | grep -q '"token"'; then
|
|
TOKEN=$(echo "$RESPONSE" | jq -r '.token // empty')
|
|
if [ -n "$TOKEN" ]; then
|
|
echo "$TOKEN"
|
|
else
|
|
echo "$RESPONSE"
|
|
fi
|
|
else
|
|
echo "Error: $RESPONSE" >&2
|
|
exit 1
|
|
fi
|