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();
}
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));
}
Aggregations