Search in sources :

Example 1 with AuthUser

use of com.amplifyframework.auth.AuthUser in project amplify-android by aws-amplify.

the class RxAuthBindingTest method testGetCurrentUser.

/**
 * Getting the current user should just pass through to the delegate, to return whatever
 * it would.
 */
@Test
public void testGetCurrentUser() {
    AuthUser expected = new AuthUser(RandomString.string(), RandomString.string());
    when(delegate.getCurrentUser()).thenReturn(expected);
    assertEquals(expected, auth.getCurrentUser());
}
Also used : AuthUser(com.amplifyframework.auth.AuthUser) Test(org.junit.Test)

Example 2 with AuthUser

use of com.amplifyframework.auth.AuthUser in project amplify-android by aws-amplify.

the class AuthComponentTest method getCurrentUser.

/**
 * Tests that the getCurrentUser method of the Auth wrapper of AWSMobileClient (AMC) returns a new
 * AWSCognitoAuthUser object containing the userId property in the plugin and the username from AMC.getUsername().
 */
@Test
public void getCurrentUser() {
    doAnswer(invocation -> USERNAME).when(mobileClient).getUsername();
    AuthUser user = authCategory.getCurrentUser();
    assertEquals(USER_SUB, user.getUserId());
    assertEquals(USERNAME, user.getUsername());
}
Also used : AuthUser(com.amplifyframework.auth.AuthUser) Test(org.junit.Test)

Example 3 with AuthUser

use of com.amplifyframework.auth.AuthUser in project amplify-android by aws-amplify.

the class AWSCognitoAuthPlugin method convertSignUpResult.

private AuthSignUpResult convertSignUpResult(@NonNull SignUpResult result, @NonNull String username) {
    UserCodeDeliveryDetails details = Objects.requireNonNull(result).getUserCodeDeliveryDetails();
    AuthCodeDeliveryDetails newDetails = details != null ? new AuthCodeDeliveryDetails(details.getDestination(), AuthCodeDeliveryDetails.DeliveryMedium.fromString(details.getDeliveryMedium()), details.getAttributeName()) : null;
    return new AuthSignUpResult(true, new AuthNextSignUpStep(result.getConfirmationState() ? AuthSignUpStep.DONE : AuthSignUpStep.CONFIRM_SIGN_UP_STEP, Collections.emptyMap(), newDetails), result.getUserSub() != null ? new AuthUser(result.getUserSub(), username) : null);
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) AuthNextSignUpStep(com.amplifyframework.auth.result.step.AuthNextSignUpStep) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) AuthUser(com.amplifyframework.auth.AuthUser)

Aggregations

AuthUser (com.amplifyframework.auth.AuthUser)3 Test (org.junit.Test)2 UserCodeDeliveryDetails (com.amazonaws.mobile.client.results.UserCodeDeliveryDetails)1 AuthCodeDeliveryDetails (com.amplifyframework.auth.AuthCodeDeliveryDetails)1 AuthSignUpResult (com.amplifyframework.auth.result.AuthSignUpResult)1 AuthNextSignUpStep (com.amplifyframework.auth.result.step.AuthNextSignUpStep)1