Generating Token Request JSON from Environment Variables

When working with New APIS we need to test them with curl prior to writing the python client. I’ve often had to hand create the JSON used for the token request, as I wrote about way back here.  Here is a simple bash script to convert the V3 environment variables into the JSON for a token request.

 

gen_token_request_json.sh

 

 

#!/bin/bash

cat << EOF
{
    "auth": {
        "identity": {
            "methods": [
                "password"
            ],
            "password": {
                "user": {
                    "domain": {
                        "name": "$OS_USER_DOMAIN_NAME"
                    },
                    "name": "$OS_USERNAME",
                    "password": "$OS_PASSWORD"
                }
            }
        },
        "scope": {
            "project": {
                "domain": {
                    "name": "$OS_PROJECT_DOMAIN_NAME"
                },
                "name": "$OS_PROJECT_NAME"
            }
        }
    }
}

EOF

Run it like this:

./gen_token_request_json.sh > token-request.json

And test it

curl -si -d @token-request.json -H "Content-type: application/json" $OS_AUTH_URL/auth/tokens

Should return a lot of JSON output.

This is for a project scoped token. Minor variations would get you unscoped or domain scoped.

Leave a Reply

Your email address will not be published. Required fields are marked *