放大Auth和Android:如何获取访客会话令牌?

问题描述

我有一个使用Amplify Auth的Android应用。我可以使用访客访问权限并 密钥,但不是会话令牌。 Postman 使用临时凭据时需要会话令牌。

根据Amplify documentation, 我使用以下代码获取密钥:

Amplify.Auth.fetchAuthSession(
    result -> {
        Log.i(TAG,"inside getGuestCredentials()...result....." + result.toString());

        AWSCognitoAuthSession cognitoAuthSession = (AWSCognitoAuthSession) result;
        Log.i(TAG,"Is user signed in: " + cognitoAuthSession.isSignedIn());

        switch (cognitoAuthSession.getIdentityId().getType()) {
            case SUCCESS:
                Log.i(TAG,"Guest IdentityId: " + cognitoAuthSession.getIdentityId().getValue());
                Log.i(TAG,"Guest access key: " + cognitoAuthSession.getAWSCredentials().getValue().getAWSAccessKeyId());
                Log.i(TAG,"Guest secret key: " + cognitoAuthSession.getAWSCredentials().getValue().getAWSSecretKey());
                String sessionToken = ((AWSSessionCredentials) mobileClient.getCredentials()).getSessionToken();
                Log.i(TAG,"Guest sessionToken: " + sessionToken);
                break;
            case FAILURE:
                Log.i(TAG,"failure Guest IdentityId not present because: " + cognitoAuthSession.getIdentityId().getError().toString());
                break;
            default:
                Log.i(TAG,"default guest session: " + cognitoAuthSession.toString());
                break;
        }
    },error -> Log.i(TAG,error.toString())
);

然后我使用AWSMobileClient的实例(使用逃生舱口获得该实例) 获取会话令牌。

这工作了一段时间,但突然我开始收到以下403消息:

“消息”:“用户:arn:aws:sts :: xxxxxx:assumed-role / amplify-xxxxxx-unauthRole / CognitoIdentityCredentials未经授权执行:execute-api:在资源上调用:arn:aws:execute- api:xxxxxyyyyyzzzz“

如何获取会话令牌?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)