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.




cat << EOF
    "auth": {
        "identity": {
            "methods": [
            "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"


Run it like this:

./ > 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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.