放大错误:auth headless init缺少以下inputParams facebookAppIdUserPool,facebookAppSecretUserPool

时间:2019-06-18 12:30:13

标签: authentication aws-amplify

G'day,

我有一个正在进行的Amplify项目。好吧,直到我运行amplify add auth并将更改推送到master为止,一切都很好。我在这里https://dev.to/dabit3/the-complete-guide-to-user-authentication-with-the-amplify-framework-2inh

遵循指示

现在我遇到以下错误,我的主人是红色的:(

在放大文档中找不到任何有用的信息。我确实尝试从此https://github.com/aws-amplify/amplify-cli/tree/master/packages/amplify-cli/sample-headless-scripts运行headless_init_env_auth.sh脚本,但这无济于事。

该错误似乎在任何地方都没有记录。

2019-06-18T11:16:53.459Z [INFO]: Error: auth headless init is missing the following inputParams facebookAppIdUserPool, facebookAppSecretUserPool, googleAppIdUserPool, googleAppSecretUserPool
                                 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:287:15)
                                 at /root/.nvm/versions/node/v8.12.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-auth/index.js:201: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)
2019-06-18T11:16:53.466Z [ERROR]: !!! Build failed
2019-06-18T11:16:53.466Z [ERROR]: !!! Non-Zero Exit Code detected```

3 个答案:

答案 0 :(得分:2)

在AUTHCONFIG中定义 facebookAppIdUserPool,facebookAppSecretUserPool,googleAppIdUserPool,googleAppSecretUserPool

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

AUTHCONFIG="{\
\"facebookAppId\":\"fbid1\",\
\"googleClientId\":\"goog\",\
\"facebookAppIdUserPool\":\"facebookAppId\",\
\"facebookAppSecretUserPool\":\"facebookAppSecret\",\
\"googleAppIdUserPool\":\"facebookAppSecret\",\
\"googleAppSecretUserPool\":\"googleAppSecret\"\
}"
AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
\"profileName\":\"default\"\
}"

AMPLIFY="{\
\"envName\":\"dev8\"\
}"
PROVIDERS="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"
CATEGORIES="{\
\"auth\":$AUTHCONFIG\
}"

amplify init \
--amplify $AMPLIFY \
--providers $PROVIDERS \
--categories $CATEGORIES \
--yes

或可以使用Amplify-CLI命令

amplify init \
--amplify "{\"envName\":\"dev\"}" \
--categories "{\"auth\":{\"googleAppIdUserPool\":\"googleAppId\",\"googleAppSecretUserPool\":\"googleAppSecret\"}}" \
--yes

答案 1 :(得分:1)

我的解决方法如下:

  1. 通过App settings> Environment variables为认证资源创建环境变量,并添加以下环境变量值:AMPLIFY_FACEBOOK_CLIENT_IDAMPLIFY_FACEBOOK_CLIENT_SECRETAMPLIFY_GOOGLE_CLIENT_IDAMPLIFY_GOOGLE_CLIENT_SECRETAMPLIFY_AMAZON_CLIENT_IDAMPLIFY_AMAZON_CLIENT_SECRET

  2. 在根文件夹amplifypush.sh中创建自己的amplify-auth-app/myamplifypush.sh(在React中创建您的项目的amplify-auth-app beind)

  3. 将您的身份验证配置添加到bash脚本中:

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

help_output () {
    echo "usage: amplify-push <--environment|-e <name>> <--simple|-s>"
    echo "  --environment  The name of the Amplify environment to use"
    echo "  --simple  Optional simple flag auto-includes stack info from env cache"
    exit 1
}

init_env () {
    ENV=$1
    AMPLIFY=$2
    PROVIDERS=$3
    CODEGEN=$4
    AWSCONFIG=$5
    CATEGORIES=$6

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

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

# if no provided environment name, use default env variable, then user override
if [[ ${ENV} = "" ]];
then
    ENV=${AWS_BRANCH}
fi

if [[ ${USER_BRANCH} != "" ]];
then
    ENV=${USER_BRANCH}
fi

# strip slashes, limit to 10 chars
ENV=$(echo ${ENV} | sed 's;\\;;g' | sed 's;\/;;g' | cut -c -10)

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

AWSCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
\"profileName\":\"default\",\
\"AmplifyAppId\":\"${AWS_APP_ID}\"\
}"
AMPLIFY="{\
\"envName\":\"${ENV}\",\
\"appId\":\"${AWS_APP_ID}\"\
}"
PROVIDERS="{\
\"awscloudformation\":${AWSCONFIG}\
}"
CODEGEN="{\
\"generateCode\":false,\
\"generateDocs\":false\
}"
CATEGORIES=""
if [[ -z ${AMPLIFY_FACEBOOK_CLIENT_ID} && -z ${AMPLIFY_GOOGLE_CLIENT_ID} && -z ${AMPLIFY_AMAZON_CLIENT_ID} ]]; then
    CATEGORIES=""
else
    AUTHCONFIG="{\
    \"facebookAppIdUserPool\":\"${AMPLIFY_FACEBOOK_CLIENT_ID}\",\
    \"facebookAppSecretUserPool\":\"${AMPLIFY_FACEBOOK_CLIENT_SECRET}\",\
    \"googleAppIdUserPool\":\"${AMPLIFY_GOOGLE_CLIENT_ID}\",\
    \"googleAppSecretUserPool\":\"${AMPLIFY_GOOGLE_CLIENT_SECRET}\",\
    \"amazonAppIdUserPool\":\"${AMPLIFY_AMAZON_CLIENT_ID}\",\
    \"amazonAppSecretUserPool\":\"${AMPLIFY_AMAZON_CLIENT_SECRET}\"\
    }"
    CATEGORIES="{\
    \"auth\":$AUTHCONFIG\
    }"
fi
# Handle old or new config file based on simple flag
if [[ ${IS_SIMPLE} ]];
then
    echo "# Getting Amplify CLI Cloud-Formation stack info from environment cache"
    export STACKINFO="$(envCache --get stackInfo)"
    init_env ${ENV} ${AMPLIFY} ${PROVIDERS} ${CODEGEN} ${AWSCONFIG} ${CATEGORIES}
    echo "# Store Amplify CLI Cloud-Formation stack info in environment cache"
    STACKINFO="$(amplify env get --json --name ${ENV})"
    envCache --set stackInfo ${STACKINFO}
    echo "STACKINFO="${STACKINFO}
else
    # old config file, above steps performed outside of this script
    init_env ${ENV} ${AMPLIFY} ${PROVIDERS} ${CODEGEN} ${AWSCONFIG} ${CATEGORIES}
fi
  1. 在放大控制台中编辑构建设置,看起来像这样:
version: 0.1
backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - chmod u+x ./myamplifypush.sh
        - ./myamplifypush.sh
frontend:
  phases:
    preBuild:
      commands:
        - npm ci
    build:
      commands:
        - npm run build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
  1. 然后重新部署

答案 2 :(得分:0)

对我来说一个简单的解决方法是从 amplify 更新环境变量。

AMPLIFY_AMAZON_CLIENT_ID

AMPLIFY_AMAZON_CLIENT_SECRET

AMPLIFY_FACEBOOK_CLIENT_ID

AMPLIFY_FACEBOOK_CLIENT_SECRET

AMPLIFY_GOOGLE_CLIENT_ID

AMPLIFY_GOOGLE_CLIENT_SECRET