Search in sources :

Example 1 with ReturningRunnable

use of com.amazonaws.mobile.client.internal.ReturningRunnable in project aws-sdk-android by aws-amplify.

the class DeviceOperations method _getDevice.

private ReturningRunnable<Device> _getDevice(final String deviceKey) {
    return new ReturningRunnable<Device>() {

        @Override
        public Device run() throws Exception {
            CognitoDevice cognitoDevice = getCognitoDevice(deviceKey);
            final GetDeviceRequest getDeviceRequest = new GetDeviceRequest();
            getDeviceRequest.setAccessToken(mobileClient.getTokens().getAccessToken().getTokenString());
            getDeviceRequest.setDeviceKey(cognitoDevice.getDeviceKey());
            final GetDeviceResult getDeviceResult = userpoolLL.getDevice(getDeviceRequest);
            return marshallDeviceTypeToDevice(getDeviceResult.getDevice());
        }
    };
}
Also used : ReturningRunnable(com.amazonaws.mobile.client.internal.ReturningRunnable) GetDeviceRequest(com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest) GetDeviceResult(com.amazonaws.services.cognitoidentityprovider.model.GetDeviceResult) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice)

Example 2 with ReturningRunnable

use of com.amazonaws.mobile.client.internal.ReturningRunnable in project aws-sdk-android by aws-amplify.

the class DeviceOperations method _listDevices.

private ReturningRunnable<ListDevicesResult> _listDevices(final Integer limit, final String paginationToken) {
    return new ReturningRunnable<ListDevicesResult>() {

        @Override
        public ListDevicesResult run() throws Exception {
            final ListDevicesRequest listDevicesRequest = new ListDevicesRequest();
            listDevicesRequest.setAccessToken(mobileClient.getTokens().getAccessToken().getTokenString());
            listDevicesRequest.setLimit(limit);
            listDevicesRequest.setPaginationToken(paginationToken);
            final com.amazonaws.services.cognitoidentityprovider.model.ListDevicesResult listDevicesResult = userpoolLL.listDevices(listDevicesRequest);
            final ArrayList<Device> devices = new ArrayList<Device>(limit);
            for (DeviceType deviceType : listDevicesResult.getDevices()) {
                devices.add(marshallDeviceTypeToDevice(deviceType));
            }
            return new ListDevicesResult(devices, listDevicesResult.getPaginationToken());
        }
    };
}
Also used : ListDevicesResult(com.amazonaws.mobile.client.results.ListDevicesResult) DeviceType(com.amazonaws.services.cognitoidentityprovider.model.DeviceType) ReturningRunnable(com.amazonaws.mobile.client.internal.ReturningRunnable) Device(com.amazonaws.mobile.client.results.Device) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) ArrayList(java.util.ArrayList) ListDevicesRequest(com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest)

Example 3 with ReturningRunnable

use of com.amazonaws.mobile.client.internal.ReturningRunnable in project aws-sdk-android by aws-amplify.

the class DeviceOperations method _rememberDevice.

private ReturningRunnable<Void> _rememberDevice(final String deviceKey, final boolean rememberDevice) {
    return new ReturningRunnable<Void>() {

        @Override
        public Void run() throws Exception {
            CognitoDevice cognitoDevice = getCognitoDevice(deviceKey);
            final UpdateDeviceStatusRequest updateDeviceStatusRequest = new UpdateDeviceStatusRequest().withAccessToken(mobileClient.getTokens().getAccessToken().getTokenString()).withDeviceKey(cognitoDevice.getDeviceKey()).withDeviceRememberedStatus(rememberDevice ? DeviceRememberedStatusType.Remembered : DeviceRememberedStatusType.Not_remembered);
            userpoolLL.updateDeviceStatus(updateDeviceStatusRequest);
            return null;
        }
    };
}
Also used : ReturningRunnable(com.amazonaws.mobile.client.internal.ReturningRunnable) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) UpdateDeviceStatusRequest(com.amazonaws.services.cognitoidentityprovider.model.UpdateDeviceStatusRequest)

Example 4 with ReturningRunnable

use of com.amazonaws.mobile.client.internal.ReturningRunnable 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)

Example 5 with ReturningRunnable

use of com.amazonaws.mobile.client.internal.ReturningRunnable in project aws-sdk-android by aws-amplify.

the class DeviceOperations method _forgetDevice.

private ReturningRunnable<Void> _forgetDevice(final String deviceKey) {
    return new ReturningRunnable<Void>() {

        @Override
        public Void run() throws Exception {
            CognitoDevice cognitoDevice = getCognitoDevice(deviceKey);
            final ForgetDeviceRequest forgetDeviceRequest = new ForgetDeviceRequest().withAccessToken(mobileClient.getTokens().getAccessToken().getTokenString()).withDeviceKey(cognitoDevice.getDeviceKey());
            userpoolLL.forgetDevice(forgetDeviceRequest);
            return null;
        }
    };
}
Also used : ReturningRunnable(com.amazonaws.mobile.client.internal.ReturningRunnable) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) ForgetDeviceRequest(com.amazonaws.services.cognitoidentityprovider.model.ForgetDeviceRequest)

Aggregations

ReturningRunnable (com.amazonaws.mobile.client.internal.ReturningRunnable)5 CognitoDevice (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice)4 CustomTabsCallback (androidx.browser.customtabs.CustomTabsCallback)1 AmazonClientException (com.amazonaws.AmazonClientException)1 InternalCallback (com.amazonaws.mobile.client.internal.InternalCallback)1 Device (com.amazonaws.mobile.client.results.Device)1 ListDevicesResult (com.amazonaws.mobile.client.results.ListDevicesResult)1 NotAuthorizedException (com.amazonaws.services.cognitoidentity.model.NotAuthorizedException)1 DeviceType (com.amazonaws.services.cognitoidentityprovider.model.DeviceType)1 ForgetDeviceRequest (com.amazonaws.services.cognitoidentityprovider.model.ForgetDeviceRequest)1 GetDeviceRequest (com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest)1 GetDeviceResult (com.amazonaws.services.cognitoidentityprovider.model.GetDeviceResult)1 GlobalSignOutRequest (com.amazonaws.services.cognitoidentityprovider.model.GlobalSignOutRequest)1 InvalidUserPoolConfigurationException (com.amazonaws.services.cognitoidentityprovider.model.InvalidUserPoolConfigurationException)1 ListDevicesRequest (com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest)1 UpdateDeviceStatusRequest (com.amazonaws.services.cognitoidentityprovider.model.UpdateDeviceStatusRequest)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 JSONException (org.json.JSONException)1