summaryrefslogtreecommitdiff
path: root/src/authorization/anastasis-authorization-sms.sh
blob: c3b105573ace7ccd7a2f67714d81bda4afc91fe5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# This file is in the public domain.
set -eu

# Check shared secrets
if [ -x "$TELESIGN_AUTH_TOKEN" ]
then
    echo "TELESIGN_AUTH_TOKEN not sent in environment"
    exit 1
fi

MESSAGE=$(cat -)
TMPFILE=$(mktemp /tmp/sms-loggingXXXXXX)
STATUS=$(curl --request POST \
     --url https://rest-api.telesign.com/v1/messaging \
     --header 'authorization: Basic $TELESIGN_AUTH_TOKEN' \
     --header 'content-type: application/x-www-form-urlencoded' \
     --data account_livecycle_event=transact \
     --data "message=$MESSAGE" \
     --data message_type=OTP \
     --data "phone_number=$1" \
     -w "%{http_code}" -s -o $TMPFILE)
case $STATUS in
    200|203|250|290|291|295)
        exit 0;
        ;;
    *)
        exit 1;
        ;;
esac
exit 1