52 lines
1.1 KiB
Bash
52 lines
1.1 KiB
Bash
#!/bin/bash
|
|
# common.sh - common functions for OPS app
|
|
|
|
# get_auth_string()
|
|
function get_auth_string() {
|
|
if ! session_verify ${cookies[sh_session]}; then
|
|
exit 0
|
|
fi
|
|
|
|
echo "Authorization: Bearer $(cat secret/authToken)"
|
|
}
|
|
|
|
# check_if_user_exists(file)
|
|
function check_if_user_exists() {
|
|
if ! session_verify ${cookies[sh_session]}; then
|
|
exit 0
|
|
fi
|
|
|
|
if [[ $1 == "refreshToken" ]]; then
|
|
if [[ $(cat secret/refreshTokens.dat | grep "${cookies[sh_session]}:") != "" ]]; then
|
|
return 1
|
|
fi
|
|
elif [[ $1 == "authToken" ]]; then
|
|
if [[ $(cat secret/authTokens.dat | grep "${cookies[sh_session]}:") != "" ]]; then
|
|
return 1
|
|
fi
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
# add_account_refreshtoken(refreshtoken)
|
|
function add_account_refreshtoken() {
|
|
if ! session_verify ${cookies[sh_session]}; then
|
|
exit 0
|
|
fi
|
|
|
|
if check_if_user_exists refreshToken; then
|
|
echo ${cookies[sh_session]}:$1 >> secret/refreshTokens.dat
|
|
fi
|
|
}
|
|
|
|
|
|
# add_account_authtoken(authtoken)
|
|
function add_account_authtoken() {
|
|
if ! session_verify ${cookies[sh_session]}; then
|
|
exit 0
|
|
fi
|
|
|
|
if check_if_user_exists authToken; then
|
|
echo ${cookies[sh_session]}:$1 >> secret/authTokens.dat
|
|
fi
|
|
} |