Search in sources :

Example 1 with HostedUIOptions

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());
}
Also used : HostedUIOptions(com.amazonaws.mobile.client.HostedUIOptions) SignInUIOptions(com.amazonaws.mobile.client.SignInUIOptions) Activity(android.app.Activity) RandomString(com.amplifyframework.testutils.random.RandomString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UserStateDetails(com.amazonaws.mobile.client.UserStateDetails) AuthSignInResult(com.amplifyframework.auth.result.AuthSignInResult) Tokens(com.amazonaws.mobile.client.results.Tokens) Test(org.junit.Test)

Example 2 with HostedUIOptions

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());
}
Also used : HostedUIOptions(com.amazonaws.mobile.client.HostedUIOptions) SignInUIOptions(com.amazonaws.mobile.client.SignInUIOptions) Activity(android.app.Activity) RandomString(com.amplifyframework.testutils.random.RandomString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UserStateDetails(com.amazonaws.mobile.client.UserStateDetails) AuthSignInResult(com.amplifyframework.auth.result.AuthSignInResult) Tokens(com.amazonaws.mobile.client.results.Tokens) Test(org.junit.Test)

Aggregations

Activity (android.app.Activity)2 HostedUIOptions (com.amazonaws.mobile.client.HostedUIOptions)2 SignInUIOptions (com.amazonaws.mobile.client.SignInUIOptions)2 UserStateDetails (com.amazonaws.mobile.client.UserStateDetails)2 Tokens (com.amazonaws.mobile.client.results.Tokens)2 AuthSignInResult (com.amplifyframework.auth.result.AuthSignInResult)2 RandomString (com.amplifyframework.testutils.random.RandomString)2 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2