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

curl -b .cookie can't work #44

Open
haskell-monad opened this issue Jun 13, 2019 · 0 comments
Open

curl -b .cookie can't work #44

haskell-monad opened this issue Jun 13, 2019 · 0 comments

Comments

@haskell-monad
Copy link

haskell-monad commented Jun 13, 2019

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
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant