spiff-arena/spiffworkflow-backend/bin/login_with_user

35 lines
992 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
function error_handler() {
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
exit "$2"
}
trap 'error_handler ${LINENO} $?' ERR
set -o errtrace -o errexit -o nounset -o pipefail
username="${1:-}"
password="${2:-}"
if [[ -z "$password" ]]; then
password="$username"
fi
if [[ -z "${1:-}" ]]; then
>&2 echo "usage: $(basename "$0") [username] [password]"
exit 1
fi
script_dir="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
if [[ -z "${REALM_NAME:-}" ]]; then
REALM_NAME=spiffworkflow
fi
access_token=$("${script_dir}/get_token" "$username" "$password" "$REALM_NAME" || echo '')
if [[ -z "$access_token" || "$access_token" == "null" ]]; then
>&2 echo "ERROR: failed to get access token for '$username'"
else
echo "access_token: ${access_token}"
2023-11-28 14:54:24 +00:00
curl -v -X POST "${BACKEND_BASE_URL}/v1.0/login_with_access_token?access_token=${access_token}&authentication_identifier=default" -H "Authorization: Bearer $access_token"
fi