Skip to content

Commit

Permalink
fix(auth): hostedUI - return success result if federation disabled (#…
Browse files Browse the repository at this point in the history
…2972)

* return success result for hostedUI sign in w/o Identity Pool
  • Loading branch information
div5yesh authored Aug 30, 2022
1 parent f035f3e commit f50b6d3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ __pycache__/
aws-android-sdk-testutils/src/main/res/raw/testconfiguration.json

# AWSCoreRuntime libs
aws-android-sdk-core/libs
aws-android-sdk-core/libs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import com.amazonaws.auth.AWSSessionCredentials;
import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.auth.CognitoCachingCredentialsProvider;
import com.amazonaws.internal.keyvaluestore.AWSKeyValueStore;
import com.amazonaws.mobile.auth.core.IdentityManager;
import com.amazonaws.mobile.auth.core.SignInStateChangeListener;
import com.amazonaws.mobile.auth.core.StartupAuthResultHandler;
Expand Down Expand Up @@ -1045,6 +1044,27 @@ protected UserStateDetails getUserStateDetails(final boolean offlineCheck) {
}
}

if (getSignInMode().equals(SignInMode.HOSTED_UI)) {
if (!federationEnabled || cognitoIdentity == null) {
// Do nothing, you are signed-in by having the token
Log.d(TAG, String.format("_hostedUISignIn without federation: Putting provider and token in store"));

try {
Tokens tokens = getHostedUITokens();
String idToken = tokens.getIdToken().getTokenString();
details.put(TOKEN_KEY, idToken);
details.put(PROVIDER_KEY, userpoolsLoginKey);
mStore.set(details);
UserState userState = UserState.SIGNED_IN;
final UserStateDetails userStateDetails = new UserStateDetails(userState, details);
return userStateDetails;
} catch (Exception e) {
UserState userState = UserState.SIGNED_OUT_USER_POOLS_TOKENS_INVALID;
return new UserStateDetails(userState, null);
}
}
}

// Online state detection
if (hasUsefulToken && !userpoolsLoginKey.equals(providerKey)) {
// TODO enhancement: check if token is expired
Expand Down Expand Up @@ -2054,6 +2074,12 @@ private void signalTokensNotAvailable(final Exception e) {
};
}

@AnyThread
private Tokens getHostedUITokens() throws Exception {
final InternalCallback<Tokens> internalCallback = new InternalCallback<Tokens>();
return internalCallback.await(() -> _getHostedUITokens(internalCallback));
}

private void _getHostedUITokens(final Callback<Tokens> callback) {
hostedUI = hostedUI.getCurrentUser();
hostedUI.setAuthHandler(new AuthHandler() {
Expand Down

0 comments on commit f50b6d3

Please sign in to comment.