gpt4 book ai didi

android - Android 应用程序中的 AWS Amplify Cognito 身份验证错误

转载 作者:行者123 更新时间:2023-12-03 21:44:45 29 4
gpt4 key购买 nike

我正在关注 Amplify 文档以将身份验证添加到我的 Android 应用程序。我收到了 AuthException在这条线上:

Amplify.addPlugin(AWSCognitoAuthPlugin())
我确实创建了一个用户池。我需要以某种方式附加它吗? AWSMobileClient 有问题, 我猜。
这是我的 Application类(class):
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=Failed to instantiate AWSMobileClient, cause=java.lang.RuntimeException: Neither Cognito Identity or Cognito UserPool was used. At least one must be present to use AWSMobileClient., recoverySuggestion=See attached exception for more details}

最佳答案

该错误表明在您的配置文件中没有找到 Identity 或 UserPool。
首先确保您已完成以下步骤:

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

  • 完成后,您应该有一个 amplifyconfiguration.jsonawsconfiguration.json在您的 app/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 - Android 应用程序中的 AWS Amplify Cognito 身份验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65303645/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com