Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

curl -b .cookie can't work #44

@haskell-monad

Description

@haskell-monad

calling ./myprovider.sh auth will generate a ./.cookie file, then execute another command (eg get-self), response 401 Authorization Required, then I manually add the access_token to -H 'Authorization: Bearer $access_token ', request again, can work normally (Amazon server Linux).

my improvement is: extract access_token from the response 'cookie' and save it to the ./.access_token file. When executing other commands, read the access_token in the file and put it into -H "Authorization: Bearer $access_token", then send the request.

authenticate() {
   ### ..... Omit other code ....
   resp=$(curl -s -X POST "$zapi/provider/login" \
        -H 'Content-Type: application/json' \
        -d '{"email":"'"$auth_email"'"
            ,"password":"'"$auth_password"'"}' \
        -c ./.cookie)

    ### ..... save access_token ....
    awk 'END{print $7}' ./.cookie > ./.access_token
    cat ./.access_token
 
    echo "$auth_ident" > .current
    echo "Authenticated as $auth_email"
}
get_self() {
    check_auth

    ###  read access_token from ./.access_token file
    access_token=$(< "./.access_token")

    ###  put it to header
    ###  still pass the ./.cookie, double insurance
    resp=$(curl -s -X GET -H "Authorization: Bearer $access_token" "$zapi/provider" -b ./.cookie)
   
    if [[ "$resp" == \{* ]]; then
        echo "$resp" | jq .
    else
        echo "$resp"
    fi
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions