尝试通过API网关从AWS检索数据时收到错误消息“ getTokens在签名时不支持获取令牌”

时间:2019-08-08 10:35:17

标签: aws-amplify

问题:
控制台显示“ getTokens在签名时不支持检索令牌”错误。     步:     1.在Android Studio上运行应用     2.登录AWS(我的应用使用放大的用户界面)     3.通过API网关从AWS检索数据->结果正常(能够检索)     4.注销并再次登录     5.通过API Gateway从AWS检索数据->结果NG(显示以​​上错误)

note:
my configuration file include: Cognito User pool and Identity pool. this is auto generate after keyin " amplify add auth" at CLI.
if i deleted  Cognito Identity pool from configuration file, issue not happen.
May i know why ?


my configuration file:
{
    "UserAgent": "aws-amplify-cli/0.1.0",
    "Version": "1.0",
    "IdentityManager": {
        "Default": {}
    },

    "CredentialsProvider": {
        "CognitoIdentity": {
            "Default": {
                "PoolId": "xxx",
                "Region": "us-east-2"
            }
        }
    },

    "CognitoUserPool": {
        "Default": {
            "PoolId": "us-east-2_xxx",
            "AppClientId": "xxx",
            "AppClientSecret": "xxx",
            "Region": "us-east-2"
        }
    }
}

sign-in code:
  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_authentication);

        AWSMobileClient.getInstance().initialize(getApplicationContext(), new Callback<UserStateDetails>() {

            @Override
            public void onResult(UserStateDetails userStateDetails) {

                switch (userStateDetails.getUserState()) {
                    case SIGNED_IN:

                                Intent i = new Intent(Authentication.this, AvailableFlavor.class);

                        break;

                    case SIGNED_OUT:
                       showSignIn();

                        break;


                    default:
                        AWSMobileClient.getInstance().signOut();
                        showSignIn();
                        break;
                }
            }

            @Override
            public void onError(Exception e) {

            }
        });
    }


    private void showSignIn() {
        try {
            AWSMobileClient.getInstance().showSignIn(this,
                    SignInUIOptions.builder().nextActivity(LoginSuccess.class)
                                                        .build());
        } catch (Exception e) {
            //  Log.e(TAG, e.toString());
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我猜错误的结尾是“getTokens 不支持在签名时检索令牌”...出? 我遇到了类似的错误,请在 app -> src -> res -> raw -> 中检查您的身份 poolId 是否正确(即使您没有使用访客访问权限,或者您只想使用用户池功能) curl -X GET 'https://nebula-eu.kampyle.com/kma/api/feedback?startDate=1483228800' \ -H 'authorization: Basic SomeKeyHere' amplifyconfiguration.json。您可以在 AWS 控制台中找到您的 poolId -> cognito -> 管理身份池 -> 单击您的池 -> 单击示例代码。:

enter image description here