Skip to content

Commit f50b6d3

Browse files
authored
fix(auth): hostedUI - return success result if federation disabled (#2972)
* return success result for hostedUI sign in w/o Identity Pool
1 parent f035f3e commit f50b6d3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ __pycache__/
7272
aws-android-sdk-testutils/src/main/res/raw/testconfiguration.json
7373

7474
# AWSCoreRuntime libs
75-
aws-android-sdk-core/libs
75+
aws-android-sdk-core/libs

aws-android-sdk-mobile-client/src/main/java/com/amazonaws/mobile/client/AWSMobileClient.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import com.amazonaws.auth.AWSSessionCredentials;
4747
import com.amazonaws.auth.AnonymousAWSCredentials;
4848
import com.amazonaws.auth.CognitoCachingCredentialsProvider;
49-
import com.amazonaws.internal.keyvaluestore.AWSKeyValueStore;
5049
import com.amazonaws.mobile.auth.core.IdentityManager;
5150
import com.amazonaws.mobile.auth.core.SignInStateChangeListener;
5251
import com.amazonaws.mobile.auth.core.StartupAuthResultHandler;
@@ -1045,6 +1044,27 @@ protected UserStateDetails getUserStateDetails(final boolean offlineCheck) {
10451044
}
10461045
}
10471046

1047+
if (getSignInMode().equals(SignInMode.HOSTED_UI)) {
1048+
if (!federationEnabled || cognitoIdentity == null) {
1049+
// Do nothing, you are signed-in by having the token
1050+
Log.d(TAG, String.format("_hostedUISignIn without federation: Putting provider and token in store"));
1051+
1052+
try {
1053+
Tokens tokens = getHostedUITokens();
1054+
String idToken = tokens.getIdToken().getTokenString();
1055+
details.put(TOKEN_KEY, idToken);
1056+
details.put(PROVIDER_KEY, userpoolsLoginKey);
1057+
mStore.set(details);
1058+
UserState userState = UserState.SIGNED_IN;
1059+
final UserStateDetails userStateDetails = new UserStateDetails(userState, details);
1060+
return userStateDetails;
1061+
} catch (Exception e) {
1062+
UserState userState = UserState.SIGNED_OUT_USER_POOLS_TOKENS_INVALID;
1063+
return new UserStateDetails(userState, null);
1064+
}
1065+
}
1066+
}
1067+
10481068
// Online state detection
10491069
if (hasUsefulToken && !userpoolsLoginKey.equals(providerKey)) {
10501070
// TODO enhancement: check if token is expired
@@ -2054,6 +2074,12 @@ private void signalTokensNotAvailable(final Exception e) {
20542074
};
20552075
}
20562076

2077+
@AnyThread
2078+
private Tokens getHostedUITokens() throws Exception {
2079+
final InternalCallback<Tokens> internalCallback = new InternalCallback<Tokens>();
2080+
return internalCallback.await(() -> _getHostedUITokens(internalCallback));
2081+
}
2082+
20572083
private void _getHostedUITokens(final Callback<Tokens> callback) {
20582084
hostedUI = hostedUI.getCurrentUser();
20592085
hostedUI.setAuthHandler(new AuthHandler() {

0 commit comments

Comments
 (0)