其他分享
首页 > 其他分享> > 如何退出aws cognito – android?

如何退出aws cognito – android?

作者:互联网

所以这是我用来签署我的用户认知的代码(我希望我正确).现在,我该如何退出?目前我有我自己的注册过程(所以没有Facebook或谷歌).

 // Callback handler for the sign-in process
    private AuthenticationHandler authenticationHandler = new AuthenticationHandler()
    {
        @Override
        public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice)
        {
            Log.d(COGNITO_LOGIN,"Login success!");
            cognitoUser.getDetailsInBackground(getDetailsHandler);
            //Now we get user from dynamoDB and store it into a local user object. 
        }
        @Override
        public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId)
        {
            Log.d(COGNITO_LOGIN,passwordET.getText().toString());
            // The API needs user sign-in credentials to continue
            AuthenticationDetails authenticationDetails = new AuthenticationDetails(userId, passwordET.getText().toString(), null);

            // Pass the user sign-in credentials to the continuation
            authenticationContinuation.setAuthenticationDetails(authenticationDetails);

            // Allow the sign-in to continue
            authenticationContinuation.continueTask();
        }
        @Override
        public void getMFACode(MultiFactorAuthenticationContinuation multiFactorAuthenticationContinuation) {
            // Multi-factor authentication is required; get the verification code from user
            multiFactorAuthenticationContinuation.setMfaCode("verificationCode");
            // Allow the sign-in process to continue
            multiFactorAuthenticationContinuation.continueTask();
        }
        @Override
        public void authenticationChallenge(ChallengeContinuation continuation) {
        }
        @Override
        public void onFailure(Exception exception)
        {
            // Sign-in failed, check exception for the cause
            Log.d(COGNITO_LOGIN,"Login failed!");
            Log.d(COGNITO_LOGIN,exception.getMessage());
        }
    };
 cognitoUser.getSessionInBackground(authenticationHandler);

解决方法:

有一种方法可以擦除或清除当前记录的用户的会话,以下是我发现的方法.

This is for fb in federated identities 
  if (fbAccessToken != null) {
                                    LoginManager.getInstance().logOut();
                                }
This is for twiiter 
                                if (mAuthManager != null) {
                                      mAuthManager.clearAuthorizationState(null);
                                }

                                // wipe data
                                CognitoSyncClientManager.getInstance()
                                        .wipeData();

标签:android,amazon-web-services,amazon-s3,amazon-cognito,aws-sdk
来源: https://codeday.me/bug/20190710/1428824.html