首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何注销aws cognito android?

如何注销aws cognito android?
EN

Stack Overflow用户
提问于 2017-01-11 12:09:50
回答 3查看 4.4K关注 0票数 4

下面是我用来登录用户的代码(我希望我是正确的)。现在,我该如何注销呢?目前我有自己的注册流程(所以还没有facebook或google )。

代码语言:javascript
复制
 // 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);
EN

回答 3

Stack Overflow用户

发布于 2017-01-12 03:33:11

您应该能够在cognitoUser对象上调用signOut,如下所示。这样做的目的是清除设备中的访问、id和刷新令牌,因此您需要再次进行身份验证。

代码语言:javascript
复制
// This has cleared all tokens and this user will have to go through the authentication process to get tokens.
user.signOut();

还有一个在服务器端撤销令牌的globalSignOut调用。

票数 1
EN

Stack Overflow用户

发布于 2017-01-11 15:18:54

有一种方法可以擦除或清除登录的当前用户的会话,下面是我到目前为止发现的方法。

代码语言:javascript
复制
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();
票数 0
EN

Stack Overflow用户

发布于 2019-06-03 21:17:27

代码语言:javascript
复制
CognitoUserPool pool = AwsCognitoHelper.getPool();
if (pool != null) {
    CognitoUser user = pool.getCurrentUser();
    if (user != null) {
        GenericHandler handler = new GenericHandler() {

            @Override
            public void onSuccess() {
            }

            @Override
            public void onFailure(Exception e) {
            }
        };
        user.globalSignOutInBackground(handler);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41582555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档