1

我刚刚开始学习 AWS Amplify,并将其集成到我的 android 项目中以对用户进行身份验证。我已成功登录,但UserState仍然是SIGNED_OUT.

AWSMobileClient.getInstance().signIn(userName, password, null, callback)

回调代码片段

fun fetchAuthenticationCallBack(): Callback<SignInResult> {
    return object : Callback<SignInResult> {
        override fun onResult(result: SignInResult?) {
            when (result?.signInState) {
                SignInState.DONE -> {
                    // AWSMobileClient.getInstance().confirmSignIn()
                    Log.d(TAG, "LOGIN SUCCESS ${AWSMobileClient.getInstance().tokens.accessToken}")
                }

                SignInState.NEW_PASSWORD_REQUIRED -> {
                    Log.d(TAG, "NEW PASSWORD CHALLENGE")
                }

                else -> {
                    // Unsupported sign-in confirmation:
                }
            }
        }

        override fun onError(e: java.lang.Exception?) {
            TODO("Not yet implemented")
        }
    }
}

我想获得 accessToken 但它给了我异常

Token does not support retrieving while user is SIGN_OUT

我在身份验证部分有什么遗漏吗?

4

1 回答 1

3

如果将来有人会遇到这个问题。

请检查您的awsconfiguration.json文件是否有问题。在我的情况下CognitoIdentity,凭据是错误的。我刚刚修复了awsconfiguration.json文件一切都按预期工作

于 2020-05-24T13:20:28.003 回答