Amplify-cli: Console multienv + auth with Google provider deployment issue

Created on 10 Dec 2018  路  3Comments  路  Source: aws-amplify/amplify-cli

Describe the bug

I am trying to set up multienv auth resources for a new web project via Amplify (using the multienv beta and the amplify console), but keep running into this error on build:

Error: auth headless init is missing the following inputParams googleClientId
    at updateConfigOnEnvInit (/root/.nvm/versions/node/v8.12.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-auth/provider-utils/awscloudformation/index.js:235:15)
    at /root/.nvm/versions/node/v8.12.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-auth/index.js:200:28
    at /root/.nvm/versions/node/v8.12.0/lib/node_modules/@aws-amplify/cli/node_modules/promise-sequential/index.js:16:18
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)

To Reproduce
Steps to reproduce the behavior:

  1. Set up a repo
  2. npx create-react-app test && cd test
  3. npx @aws-amplify/cli@multienv init
  4. npx @aws-amplify/cli@multienv auth add (custom settings, use 3rd party auth providers -- I'm using google and have provided a client ID)
  5. git commit -am "test" && git push origin master
  6. Go to https://console.aws.amazon.com/amplify/home?region=us-east-1#/create and connect the repo
  7. Wait for first build, see error

Expected behavior

I would expect Amplify not to fail for this use case, probably by using the config in checked-in to amplify/team-provider-info.json

More/better docs would be great too as these features stabilize :)

auth question

Most helpful comment

Some things I wish I'd known when troubleshooting this...

In case it's not immediately clear, the above custom build script above is a modification of the actual default amplifyPush.sh used in Amplify Console.

You can commit this script as a file in your repo named for example as amplify-custom-push (be sure to change the permissions of the file using chmod to be executable, or else you'll get an error on builds). Then, modify your build command to point to this file on the Amplify Console.

When a build kicks off after you push a commit, if you happen to see a cryptic build error that says something like

/root/.nvm/versions/node/v10.16.0/lib/node_modules/@aws-amplify/cli/node_modules/gluegun/build/index.js:13
throw up;
^
SyntaxError: Unexpected token } in JSON at position 264
at JSON.parse ()

It's possibly because you left a comma , before the end backslash of your final key, as the above custom script does by accident if you don't modify it.

AUTHCONFIG="{\
\"googleClientId\":\"${GOOGLE_CLIENT_ID}\",\
}"

(There shouldn't be a comma in the above, since it's the last item in the list).

All 3 comments

@nason thank you for reporting this issue. We intentionally don't want users to share clientIds in different environment. We expect users to pass clientId for each auth provider, but there is no good way to do it using the Amplify Console. We will investigate/implement a right way to do this but in the mean time you could use the following workaround

Amplify console has amplifyPush wrapper script. The script doesn't take third party auth in to account during initialization. You could set GOOGLE_CLIENT_ID env variable and run the following script instead of amplifyPush in your build spec

#!/usr/bin/env bash
set -e
IFS='|'

help_output () {
    echo "usage: amplify-push <--environment|-e <name>>"
    echo "  --environment  The name of the Amplify environment to use"
    exit 1
}

POSITIONAL=()
while [[ $# -gt 0 ]]
    do
    key="$1"
    case ${key} in
        -e|--environment)
        ENV=$2
        shift
        ;;
        -r|--region)
        REGION=$2
        shift
        ;;
        *)
        POSITIONAL+=("$1")
        shift
        ;;
    esac
done
set -- "${POSITIONAL[@]}"

# Check valid environment name
if [[ -z ${ENV} || "${ENV}" =~ [^a-zA-Z0-9\-]+ ]] ; then help_output ; fi

AWSCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
\"profileName\":\"default\"\
}"
AMPLIFY="{\
\"envName\":\"${ENV}\"\
}"
PROVIDERS="{\
\"awscloudformation\":${AWSCONFIG}\
}"
CODEGEN="{\
\"generateCode\":false,\
\"generateDocs\":false\
}"

AUTHCONFIG="{\
\"googleClientId\":\"${GOOGLE_CLIENT_ID}\",\
}"

CATEGORIES="{\
\"auth\":$AUTHCONFIG\
}"

echo "# Start initializing Amplify environment: ${ENV}"
if [[ -z ${STACKINFO} ]];
then
    echo "# Initializing new Amplify environment: ${ENV} (amplify init)"
    amplify init --amplify ${AMPLIFY} --providers ${PROVIDERS} --codegen ${CODEGEN} --categories $CATEGORIES  --yes;
    echo "# Environment ${ENV} details:"
    amplify env get --name ${ENV}
else
    echo "# Importing Amplify environment: ${ENV} (amplify env add)"
    amplify env add --name ${ENV} --config "${STACKINFO}" --awsInfo ${AWSCONFIG} --categories $CATEGORIES  --yes;
    echo "# Initializing existing Amplify environment: ${ENV} (amplify init)"
    amplify init --amplify ${AMPLIFY} --providers ${PROVIDERS} --codegen ${CODEGEN} --categories $CATEGORIES --yes;
    echo "# Environment ${ENV} details:"
    amplify env get --name ${ENV}
fi
echo "# Done initializing Amplify environment: ${ENV}"

Closing this issue for now, feel free to re-open it if needed.

Some things I wish I'd known when troubleshooting this...

In case it's not immediately clear, the above custom build script above is a modification of the actual default amplifyPush.sh used in Amplify Console.

You can commit this script as a file in your repo named for example as amplify-custom-push (be sure to change the permissions of the file using chmod to be executable, or else you'll get an error on builds). Then, modify your build command to point to this file on the Amplify Console.

When a build kicks off after you push a commit, if you happen to see a cryptic build error that says something like

/root/.nvm/versions/node/v10.16.0/lib/node_modules/@aws-amplify/cli/node_modules/gluegun/build/index.js:13
throw up;
^
SyntaxError: Unexpected token } in JSON at position 264
at JSON.parse ()

It's possibly because you left a comma , before the end backslash of your final key, as the above custom script does by accident if you don't modify it.

AUTHCONFIG="{\
\"googleClientId\":\"${GOOGLE_CLIENT_ID}\",\
}"

(There shouldn't be a comma in the above, since it's the last item in the list).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adriatikgashi picture adriatikgashi  路  3Comments

ArunPrasathSubramani picture ArunPrasathSubramani  路  3Comments

kstro21 picture kstro21  路  3Comments

amlcodes picture amlcodes  路  3Comments

MageMasher picture MageMasher  路  3Comments