如何使用 curl 进行单点登录网站或页面

如何使用 curl 进行单点登录网站或页面

我已经编写了一个 shell 脚本,但它不起作用。我得到的是空响应,而它应该首先返回一个令牌,并且还应该登录然后注册 API。

这就是我的 shell 脚本要执行的任务。

#!/bin/bash
# Begin

TEMP=$(getopt -n "$0" -a -l "base_url:,auth0_url:,register_url:,username:,password:,openapi_spec:,base_path:,label:,test_email:" -- -- "$@")

[ $? -eq 0 ] || exit

eval set -- "$TEMP"

while [ $# -gt 0 ]; do
    case "$1" in
        --base_url) BASE_URL="$2"; shift ;;
        --auth0_url) AUTH0_URL="$2"; shift ;;
        --register_url) REGISTER_URL="$2"; shift ;;
        --username) TEST_USER="$2"; shift ;;
        --password) TEST_PWD="$2"; shift ;;
        --openapi_spec) OPENAPI_SPEC="$2"; shift ;;
        --base_path) BASEPATH_SPEC="$2"; shift ;;
        --label) LABEL="$2"; shift ;;
        --test_email) TEST_EMAIL="$2"; shift ;;
        --) shift ;;
    esac
    shift
done

# Set defaults for configurable options
BASE_URL=${BASE_URL:-"https://dev.cloudnetwork.in"}
AUTH0_URL=${AUTH0_URL:-"https://dev-yxxxxxxx1.us.auth0.com"}
REGISTER_URL=${REGISTER_URL:-"https://dev.cloudnetwork.in/apis/register"}


#f [ "$BASE_URL" = "" ];
#then
#    BASE_URL="https://dev.cloudnetwork.in"
#fi

### IM STRUCK AT THIS CURL COMMAND ###
echo " "
token=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${TEST_USER}'", "password": "'${TEST_PWD}'"}'  ${AUTH0_URL}/login ${BASE_URL}/login ${REGISTER_URL}/login | jq -r .token)

echo "generated token is:" $token

echo " "

data=$(curl -k -s -H "Accept: application/json" -H "Content-Type: application/json" --location --request POST "https://dev.cloudnetwork.in/api/v1/api/test" --header "Authorization: Bearer $token" -d  '{"base_url":"'"${BASE_URL}"'","auth0_url":"'"${AUTH0_URL}"'","register_url":"'"${REGISTER_URL}"'","openapi_spec":"'"${OPENAPI_SPEC}"'","base_path":"'"${BASEPATH_SPEC}"'","label":"'"${LABEL}"'","test_email":"'"${TEST_EMAIL}"'"}' | jq -r .token)

label_name=$(jq -r '.label')
created_email=$(jq -r '.created_by_email')

echo "Successfully created the API Register."
echo "LabelName: $label_name"
echo "CreatedEmail: $created_email"
echo 'Script Execution is Done.'
echo "Successfully created $NoProjectsToCreate projects in $TEST_HOSTNAME env

这是我的输出命令

./dev-registry.sh --base_url "https://dev.cloudnetwork.in" --auth0_url "https://dev-yxxxxxxxx1.us.auth0.com" --register_url "https://dev.cloudnetwork.in/apis/register" --username "[email protected]" --password "123456" --openapi_spec "https://xxxxxx.yaml" --base_path "https://xxxxxxx/v2" --label "Demo" --test_email "[email protected]"

这是我的网站登录浏览器响应,下面显示了我从这里获取并添加到 curl 内的 shell 脚本中的所有详细信息

 {
    BASE_URL: 'https://dev.cloudnetwork.in',
    AUTH0_URL: 'https://dev-yxxxxxxxxx1.us.auth0.com',
    USERNAME: '[email protected]',
    PASSWORD: '123456',
    REGISTER_URL:'https://dev.cloudnetwork.in/apis/register',
  },


1. GENERAL
Request URL:     https://dev.cloudnetwork.in/api/v1/api/test
Request Method:  POST

2. Request Header
authority:       api.dev.cloudnetwork.in
method:          POST
path:            /api/v1/api/test
Authorization:   Bearer
eyJhxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxeaLvIBUOsH6gGQ1xxxxxxxxxxxxxxxx0huyw

3. Payload
openapi_spec:      "https://xxxxx/xxxxx.yaml"
base_path:          "https://xxxxxxx/v2"
test_email:   "[email protected]"
label:              "demo"

{"openapi_spec":"https://xxxxxxxx.yaml","base_path":"https://xxxxxxxx/v2","label":"demossss"}

因此,使用上述详细信息,我将提取令牌、登录并注册 API。我想从上面的 shell 脚本执行相同操作,但它返回一个空响应。

我不知道我错在哪里。

相关内容