use of com.amazonaws.mobile.client.HostedUIOptions in project amplify-android by aws-amplify.
the class AuthComponentTest method signInWithWebUI.
/**
* Tests that the signInWithWebUI method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.showSignIn
* with the proper parameters and converts the returned result to the proper AuthSignInResult.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void signInWithWebUI() throws AuthException {
Map<String, String> additionalInfoMap = Collections.singletonMap("testKey", "testVal");
UserStateDetails userStateResult = new UserStateDetails(UserState.SIGNED_IN, additionalInfoMap);
doAnswer(invocation -> {
Callback<UserStateDetails> callback = invocation.getArgument(2);
callback.onResult(userStateResult);
return null;
}).when(mobileClient).showSignIn(any(), any(), any());
Tokens tokensResult = new Tokens(ACCESS_TOKEN, ID_TOKEN, REFRESH_TOKEN);
doAnswer(invocation -> {
Callback<Tokens> callback = invocation.getArgument(0);
callback.onResult(tokensResult);
return null;
}).when(mobileClient).getTokens(any());
Activity activity = new Activity();
String federationProviderName = "testFedProvider";
String idpIdentifier = "testIdpID";
String browserPackage = "org.mozilla.firefox";
List<String> scopes = Collections.singletonList("scope");
Map<String, String> signInMap = Collections.singletonMap("signInKey", "signInVal");
Map<String, String> signOutMap = Collections.singletonMap("signOutKey", "signOutVal");
Map<String, String> tokensMap = Collections.singletonMap("tokensKey", "tokensVal");
AuthSignInResult result = synchronousAuth.signInWithWebUI(activity, AWSCognitoAuthWebUISignInOptions.builder().federationProviderName(federationProviderName).idpIdentifier(idpIdentifier).scopes(scopes).signInQueryParameters(signInMap).signOutQueryParameters(signOutMap).tokenQueryParameters(tokensMap).browserPackage(browserPackage).build());
assertTrue(result.isSignInComplete());
assertEquals(AuthSignInStep.DONE, result.getNextStep().getSignInStep());
assertEquals(additionalInfoMap, result.getNextStep().getAdditionalInfo());
ArgumentCaptor<SignInUIOptions> optionsCaptor = ArgumentCaptor.forClass(SignInUIOptions.class);
verify(mobileClient).showSignIn(eq(activity), optionsCaptor.capture(), any());
SignInUIOptions signInUIOptions = optionsCaptor.getValue();
HostedUIOptions hostedUIOptions = signInUIOptions.getHostedUIOptions();
assertNotNull(hostedUIOptions);
assertNull(hostedUIOptions.getIdentityProvider());
assertEquals(federationProviderName, hostedUIOptions.getFederationProviderName());
assertEquals(idpIdentifier, hostedUIOptions.getIdpIdentifier());
assertEquals(browserPackage, signInUIOptions.getBrowserPackage());
assertArrayEquals(scopes.toArray(), hostedUIOptions.getScopes());
assertEquals(signInMap, hostedUIOptions.getSignInQueryParameters());
assertEquals(signOutMap, hostedUIOptions.getSignOutQueryParameters());
assertEquals(tokensMap, hostedUIOptions.getTokenQueryParameters());
}
use of com.amazonaws.mobile.client.HostedUIOptions in project amplify-android by aws-amplify.
the class AuthComponentTest method signInWithSocialWebUI.
/**
* Tests that the signInWithSocialWebUI method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.showSignIn
* with the proper parameters and converts the returned result to the proper AuthSignInResult.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void signInWithSocialWebUI() throws AuthException {
Map<String, String> additionalInfoMap = Collections.singletonMap("testKey", "testVal");
UserStateDetails userStateResult = new UserStateDetails(UserState.SIGNED_IN, additionalInfoMap);
doAnswer(invocation -> {
Callback<UserStateDetails> callback = invocation.getArgument(2);
callback.onResult(userStateResult);
return null;
}).when(mobileClient).showSignIn(any(), any(), any());
Tokens tokensResult = new Tokens(ACCESS_TOKEN, ID_TOKEN, REFRESH_TOKEN);
doAnswer(invocation -> {
Callback<Tokens> callback = invocation.getArgument(0);
callback.onResult(tokensResult);
return null;
}).when(mobileClient).getTokens(any());
Activity activity = new Activity();
AuthSignInResult result = synchronousAuth.signInWithSocialWebUI(AuthProvider.facebook(), activity);
assertTrue(result.isSignInComplete());
assertEquals(AuthSignInStep.DONE, result.getNextStep().getSignInStep());
assertEquals(additionalInfoMap, result.getNextStep().getAdditionalInfo());
ArgumentCaptor<SignInUIOptions> optionsCaptor = ArgumentCaptor.forClass(SignInUIOptions.class);
verify(mobileClient).showSignIn(eq(activity), optionsCaptor.capture(), any());
HostedUIOptions hostedUIOptions = optionsCaptor.getValue().getHostedUIOptions();
assertNotNull(hostedUIOptions);
assertEquals("Facebook", hostedUIOptions.getIdentityProvider());
}
Aggregations