|
46 | 46 | import com.amazonaws.auth.AWSSessionCredentials; |
47 | 47 | import com.amazonaws.auth.AnonymousAWSCredentials; |
48 | 48 | import com.amazonaws.auth.CognitoCachingCredentialsProvider; |
49 | | -import com.amazonaws.internal.keyvaluestore.AWSKeyValueStore; |
50 | 49 | import com.amazonaws.mobile.auth.core.IdentityManager; |
51 | 50 | import com.amazonaws.mobile.auth.core.SignInStateChangeListener; |
52 | 51 | import com.amazonaws.mobile.auth.core.StartupAuthResultHandler; |
@@ -1045,6 +1044,27 @@ protected UserStateDetails getUserStateDetails(final boolean offlineCheck) { |
1045 | 1044 | } |
1046 | 1045 | } |
1047 | 1046 |
|
| 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 | + |
1048 | 1068 | // Online state detection |
1049 | 1069 | if (hasUsefulToken && !userpoolsLoginKey.equals(providerKey)) { |
1050 | 1070 | // TODO enhancement: check if token is expired |
@@ -2054,6 +2074,12 @@ private void signalTokensNotAvailable(final Exception e) { |
2054 | 2074 | }; |
2055 | 2075 | } |
2056 | 2076 |
|
| 2077 | + @AnyThread |
| 2078 | + private Tokens getHostedUITokens() throws Exception { |
| 2079 | + final InternalCallback<Tokens> internalCallback = new InternalCallback<Tokens>(); |
| 2080 | + return internalCallback.await(() -> _getHostedUITokens(internalCallback)); |
| 2081 | + } |
| 2082 | + |
2057 | 2083 | private void _getHostedUITokens(final Callback<Tokens> callback) { |
2058 | 2084 | hostedUI = hostedUI.getCurrentUser(); |
2059 | 2085 | hostedUI.setAuthHandler(new AuthHandler() { |
|
0 commit comments