Search in sources :

Example 1 with GlobalSignOutRequest

use of com.amazonaws.services.cognitoidentityprovider.model.GlobalSignOutRequest in project aws-sdk-android by aws-amplify.

the class CognitoUser method globalSignOutInternal.

/**
 * Internal method to Sign-Out from all devices of this user.
 *
 * @param session REQUIRED: {@link GenericHandler} callback.
 */
private void globalSignOutInternal(CognitoUserSession session) {
    // Check if session is valid
    if (session == null) {
        throw new CognitoNotAuthorizedException("user is not authenticated");
    }
    if (!session.isValid()) {
        throw new CognitoNotAuthorizedException("user is not authenticated");
    }
    final GlobalSignOutRequest globalSignOutRequest = new GlobalSignOutRequest();
    globalSignOutRequest.setAccessToken(getCachedSession().getAccessToken().getJWTToken());
    cognitoIdentityProviderClient.globalSignOut(globalSignOutRequest);
}
Also used : GlobalSignOutRequest(com.amazonaws.services.cognitoidentityprovider.model.GlobalSignOutRequest) CognitoNotAuthorizedException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)

Example 2 with GlobalSignOutRequest

use of com.amazonaws.services.cognitoidentityprovider.model.GlobalSignOutRequest in project aws-sdk-android by aws-amplify.

the class OAuth2Utils method _signOut.

private ReturningRunnable<Void> _signOut(final SignOutOptions signOutOptions) {
    return new ReturningRunnable<Void>() {

        @Override
        public Void run() throws Exception {
            if (signOutOptions.isSignOutGlobally()) {
                final GlobalSignOutRequest globalSignOutRequest = new GlobalSignOutRequest();
                globalSignOutRequest.setAccessToken(getTokens().getAccessToken().getTokenString());
                userpoolLL.globalSignOut(globalSignOutRequest);
            }
            if (signOutOptions.isInvalidateTokens()) {
                if (userpool != null) {
                    userpool.getCurrentUser().revokeTokens();
                }
                if (hostedUI != null) {
                    if (signOutOptions.getBrowserPackage() != null) {
                        hostedUI.setBrowserPackage(signOutOptions.getBrowserPackage());
                    }
                    hostedUI.signOut();
                } else if (mOAuth2Client != null) {
                    final CountDownLatch latch = new CountDownLatch(1);
                    final JSONObject hostedUIJSON = getHostedUIJSON();
                    final String signOutUriString = hostedUIJSON.getString("SignOutURI");
                    final Uri.Builder uriBuilder = Uri.parse(signOutUriString).buildUpon();
                    if (getHostedUIJSON().optString("SignOutRedirectURI", null) != null) {
                        uriBuilder.appendQueryParameter("redirect_uri", getHostedUIJSON().getString("SignOutRedirectURI"));
                    }
                    final JSONObject signOutQueryParametersJSON = hostedUIJSON.getJSONObject("SignOutQueryParameters");
                    if (signOutQueryParametersJSON != null) {
                        final Iterator<String> keysIterator = signOutQueryParametersJSON.keys();
                        while (keysIterator.hasNext()) {
                            String key = keysIterator.next();
                            uriBuilder.appendQueryParameter(key, signOutQueryParametersJSON.getString(key));
                        }
                    }
                    final Exception[] signOutError = new Exception[1];
                    mOAuth2Client.signOut(uriBuilder.build(), new Callback<Void>() {

                        @Override
                        public void onResult(Void result) {
                            latch.countDown();
                        }

                        @Override
                        public void onError(Exception e) {
                            signOutError[0] = e;
                            latch.countDown();
                        }
                    });
                    latch.await();
                    if (signOutError[0] != null) {
                        throw signOutError[0];
                    }
                }
            }
            signOut();
            return null;
        }
    };
}
Also used : CustomTabsCallback(androidx.browser.customtabs.CustomTabsCallback) InternalCallback(com.amazonaws.mobile.client.internal.InternalCallback) ReturningRunnable(com.amazonaws.mobile.client.internal.ReturningRunnable) JSONObject(org.json.JSONObject) GlobalSignOutRequest(com.amazonaws.services.cognitoidentityprovider.model.GlobalSignOutRequest) Iterator(java.util.Iterator) CountDownLatch(java.util.concurrent.CountDownLatch) JSONException(org.json.JSONException) InvalidUserPoolConfigurationException(com.amazonaws.services.cognitoidentityprovider.model.InvalidUserPoolConfigurationException) AmazonClientException(com.amazonaws.AmazonClientException) NotAuthorizedException(com.amazonaws.services.cognitoidentity.model.NotAuthorizedException)

Aggregations

GlobalSignOutRequest (com.amazonaws.services.cognitoidentityprovider.model.GlobalSignOutRequest)2 CustomTabsCallback (androidx.browser.customtabs.CustomTabsCallback)1 AmazonClientException (com.amazonaws.AmazonClientException)1 InternalCallback (com.amazonaws.mobile.client.internal.InternalCallback)1 ReturningRunnable (com.amazonaws.mobile.client.internal.ReturningRunnable)1 CognitoNotAuthorizedException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)1 NotAuthorizedException (com.amazonaws.services.cognitoidentity.model.NotAuthorizedException)1 InvalidUserPoolConfigurationException (com.amazonaws.services.cognitoidentityprovider.model.InvalidUserPoolConfigurationException)1 Iterator (java.util.Iterator)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1