Android应用程序中的AWSAmplifyCognitoAuth错误

我正在按照 Amplify 文档向我的 Android 应用程序添加身份验证。我AuthException在这条线上得到一个:

Amplify.addPlugin(AWSCognitoAuthPlugin())

我确实创建了一个用户池。我需要以某种方式附加它吗?有一些问题AWSMobileClient,我猜。

这是我的Application课:

class AppUtils : Application() {
    override fun onCreate() {
        super.onCreate()
        try {
            Amplify.addPlugin(AWSCognitoAuthPlugin())
            Amplify.configure(applicationContext)
            Log.d(TAG, "Initialized Amplify")
        } catch (error: AmplifyException) {
            Log.e(TAG, "Could not initialize Amplify", error)
        }
    }
}

这是出现在 logcat 中的错误:

AuthException{message=无法实例化 AWSMobileClient,cause=java.lang.RuntimeException:未使用 Cognito Identity 或 Cognito UserPool。必须至少存在一个才能使用 AWSMobileClient。, recoverySuggestion=有关更多详细信息,请参阅附加的例外情况}

回答

该错误表明在您的配置文件中没有找到 Identity 或 UserPool。

首先确保您已完成以下步骤:

  • 放大初始化
  • 放大添加身份验证
  • 放大推

完成后,您的目录中应该有一个amplifyconfiguration.json和。awsconfiguration.jsonapp/src/main/res/raw

amplifyconfiguration.json应该是这样的:

{
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                            "Region": "us-east-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "us-east-1_xxxxxxxxx",
                        "AppClientId": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
                        "AppClientSecret":
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                        "Region": "us-east-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH"
                    }
                }
            }
        }
    }
}

awsconfiguration.json应该是这样的:

{
    "UserAgent": "aws-amplify-cli/0.1.0",
    "Version": "0.1.0",
    "IdentityManager": {
        "Default": {}
    },
    "CredentialsProvider": {
        "CognitoIdentity": {
            "Default": {
                "PoolId": "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                "Region": "us-east-1"
            }
        }
    },
    "CognitoUserPool": {
        "Default": {
            "PoolId": "us-east-1_xxxxxxxxx",
            "AppClientId": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
            "AppClientSecret":
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "Region": "us-east-1"
        }
    },
    "Auth": {
        "Default": {
            "authenticationFlowType": "USER_SRP_AUTH"
        }
    }
}


以上是Android应用程序中的AWSAmplifyCognitoAuth错误的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>