Search in sources :

Example 6 with AuthUserSession

use of com.amazonaws.mobileconnectors.cognitoauth.AuthUserSession in project aws-sdk-android by aws-amplify.

the class OAuth2Utils method _initializeHostedUI.

private void _initializeHostedUI(JSONObject hostedUIJSON) throws JSONException {
    Log.d(TAG, "initialize: Cognito HostedUI client detected");
    final JSONArray scopesJSONArray = hostedUIJSON.getJSONArray("Scopes");
    final Set<String> scopes = new HashSet<String>();
    for (int i = 0; i < scopesJSONArray.length(); i++) {
        scopes.add(scopesJSONArray.getString(i));
    }
    if (mUserPoolPoolId == null) {
        throw new IllegalStateException("User pool Id must be available through user pool setting");
    }
    hostedUI = getHostedUI(hostedUIJSON).setPersistenceEnabled(mIsPersistenceEnabled).setAuthHandler(new AuthHandler() {

        @Override
        public void onSuccess(AuthUserSession session) {
        // Ignored because this is used to pre-warm the session
        }

        @Override
        public void onSignout() {
        // Ignored because this is used to pre-warm the session
        }

        @Override
        public void onFailure(Exception e) {
        // Ignored because this is used to pre-warm the session
        }
    }).build();
}
Also used : AuthHandler(com.amazonaws.mobileconnectors.cognitoauth.handlers.AuthHandler) JSONArray(org.json.JSONArray) AuthUserSession(com.amazonaws.mobileconnectors.cognitoauth.AuthUserSession) JSONException(org.json.JSONException) InvalidUserPoolConfigurationException(com.amazonaws.services.cognitoidentityprovider.model.InvalidUserPoolConfigurationException) AmazonClientException(com.amazonaws.AmazonClientException) NotAuthorizedException(com.amazonaws.services.cognitoidentity.model.NotAuthorizedException) HashSet(java.util.HashSet)

Example 7 with AuthUserSession

use of com.amazonaws.mobileconnectors.cognitoauth.AuthUserSession in project aws-sdk-android by aws-amplify.

the class AWSMobileClientPersistenceWithRestartabilityTest method mockHostedUISignIn.

// Note that most tests create valid JWT tokens with expiry dates in the past. However, because
// we want to assert that HostedUI can get tokens, without making a network call to refresh a
// session, we're going to mock up valid session data, and ensure we call `getTokens` with
// `waitForSignIn = false`.
private void mockHostedUISignIn() throws JSONException {
    AuthUserSession authUserSession = new AuthUserSession(new IdToken(getValidJWT(3600L)), new AccessToken(getValidJWT(3600L)), new RefreshToken(getValidJWT(360000L)));
    Context targetContext = ApplicationProvider.getApplicationContext();
    AWSKeyValueStore storeForHostedUI = new AWSKeyValueStore(targetContext, "CognitoIdentityProviderCache", true);
    final Set<String> scopes = new HashSet<String>(Arrays.asList("aws.cognito.signin.user.admin", "phone", "openid", "profile", "email"));
    LocalDataManager.cacheSession(storeForHostedUI, targetContext, getPackageConfigure().getString("app_client_id"), getPackageConfigure().getString("username"), authUserSession, scopes);
    // Set the AWSMobileClient metadata that is specific to HostedUI
    auth.mStore.set(FEDERATION_ENABLED_KEY, "true");
    auth.mStore.set(HOSTED_UI_KEY, "dummyJson");
    auth.mStore.set(SIGN_IN_MODE, SignInMode.HOSTED_UI.toString());
    auth.mStore.set(PROVIDER_KEY, auth.getLoginKey());
    auth.mStore.set(TOKEN_KEY, getValidJWT(3600L));
}
Also used : Context(android.content.Context) IdToken(com.amazonaws.mobileconnectors.cognitoauth.tokens.IdToken) RefreshToken(com.amazonaws.mobileconnectors.cognitoauth.tokens.RefreshToken) AccessToken(com.amazonaws.mobileconnectors.cognitoauth.tokens.AccessToken) AuthUserSession(com.amazonaws.mobileconnectors.cognitoauth.AuthUserSession) AWSKeyValueStore(com.amazonaws.internal.keyvaluestore.AWSKeyValueStore) HashSet(java.util.HashSet)

Aggregations

AuthUserSession (com.amazonaws.mobileconnectors.cognitoauth.AuthUserSession)7 AccessToken (com.amazonaws.mobileconnectors.cognitoauth.tokens.AccessToken)4 IdToken (com.amazonaws.mobileconnectors.cognitoauth.tokens.IdToken)4 RefreshToken (com.amazonaws.mobileconnectors.cognitoauth.tokens.RefreshToken)4 AmazonClientException (com.amazonaws.AmazonClientException)3 AuthHandler (com.amazonaws.mobileconnectors.cognitoauth.handlers.AuthHandler)3 NotAuthorizedException (com.amazonaws.services.cognitoidentity.model.NotAuthorizedException)3 InvalidUserPoolConfigurationException (com.amazonaws.services.cognitoidentityprovider.model.InvalidUserPoolConfigurationException)3 JSONException (org.json.JSONException)3 InvalidParameterException (java.security.InvalidParameterException)2 HashSet (java.util.HashSet)2 JSONObject (org.json.JSONObject)2 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 AnyThread (androidx.annotation.AnyThread)1 WorkerThread (androidx.annotation.WorkerThread)1 CustomTabsCallback (androidx.browser.customtabs.CustomTabsCallback)1 AWSKeyValueStore (com.amazonaws.internal.keyvaluestore.AWSKeyValueStore)1 InternalCallback (com.amazonaws.mobile.client.internal.InternalCallback)1 ReturningRunnable (com.amazonaws.mobile.client.internal.ReturningRunnable)1