Search in sources :

Example 1 with SessionRecord

use of com.firebase.ui.auth.util.data.EmailLinkPersistenceManager.SessionRecord in project FirebaseUI-Android by firebase.

the class EmailLinkPersistanceManagerTest method testSaveAndRetrieveEmailForLink.

@Test
public void testSaveAndRetrieveEmailForLink() {
    mPersistenceManager.saveEmail(ApplicationProvider.getApplicationContext(), TestConstants.EMAIL, TestConstants.SESSION_ID, TestConstants.UID);
    SessionRecord sessionRecord = mPersistenceManager.retrieveSessionRecord(ApplicationProvider.getApplicationContext());
    assertThat(sessionRecord.getEmail()).isEqualTo(TestConstants.EMAIL);
    assertThat(sessionRecord.getSessionId()).isEqualTo(TestConstants.SESSION_ID);
    assertThat(sessionRecord.getAnonymousUserId()).isEqualTo(TestConstants.UID);
}
Also used : SessionRecord(com.firebase.ui.auth.util.data.EmailLinkPersistenceManager.SessionRecord) Test(org.junit.Test)

Example 2 with SessionRecord

use of com.firebase.ui.auth.util.data.EmailLinkPersistenceManager.SessionRecord in project FirebaseUI-Android by firebase.

the class EmailLinkPersistanceManagerTest method testSaveAndRetrieveIdpResonseForLinking_noSavedEmail_expectNothingSaved.

@Test
public void testSaveAndRetrieveIdpResonseForLinking_noSavedEmail_expectNothingSaved() {
    IdpResponse response = buildIdpResponse();
    mPersistenceManager.saveIdpResponseForLinking(ApplicationProvider.getApplicationContext(), response);
    SessionRecord sessionRecord = mPersistenceManager.retrieveSessionRecord(ApplicationProvider.getApplicationContext());
    assertThat(sessionRecord).isNull();
}
Also used : IdpResponse(com.firebase.ui.auth.IdpResponse) SessionRecord(com.firebase.ui.auth.util.data.EmailLinkPersistenceManager.SessionRecord) Test(org.junit.Test)

Example 3 with SessionRecord

use of com.firebase.ui.auth.util.data.EmailLinkPersistenceManager.SessionRecord in project FirebaseUI-Android by firebase.

the class EmailLinkSignInHandler method startSignIn.

public void startSignIn() {
    setResult(Resource.forLoading());
    String link = getArguments().emailLink;
    if (!getAuth().isSignInWithEmailLink(link)) {
        setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.INVALID_EMAIL_LINK_ERROR)));
        return;
    }
    final EmailLinkPersistenceManager persistenceManager = EmailLinkPersistenceManager.getInstance();
    SessionRecord sessionRecord = persistenceManager.retrieveSessionRecord(getApplication());
    EmailLinkParser parser = new EmailLinkParser(link);
    String sessionIdFromLink = parser.getSessionId();
    String anonymousUserIdFromLink = parser.getAnonymousUserId();
    String oobCodeFromLink = parser.getOobCode();
    String providerIdFromLink = parser.getProviderId();
    boolean forceSameDevice = parser.getForceSameDeviceBit();
    if (isDifferentDeviceFlow(sessionRecord, sessionIdFromLink)) {
        if (TextUtils.isEmpty(sessionIdFromLink)) {
            // There should always be a valid session ID in the link
            setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.INVALID_EMAIL_LINK_ERROR)));
            return;
        }
        if (forceSameDevice || !TextUtils.isEmpty(anonymousUserIdFromLink)) {
            // In both cases, the link was meant to be completed on the same device.
            // For anonymous user upgrade, we don't support the cross device flow.
            setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.EMAIL_LINK_WRONG_DEVICE_ERROR)));
            return;
        }
        // If we have no SessionRecord/there is a session ID mismatch, this means that we were
        // not the ones to send the link. The only way forward is to prompt the user for their
        // email before continuing the flow. We should only do that after validating the link.
        determineDifferentDeviceErrorFlowAndFinish(oobCodeFromLink, providerIdFromLink);
        return;
    }
    if (anonymousUserIdFromLink != null) {
        // Same device flow, need to ensure uids match
        if (getAuth().getCurrentUser() == null || (getAuth().getCurrentUser().isAnonymous() && !anonymousUserIdFromLink.equals(getAuth().getCurrentUser().getUid()))) {
            setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR)));
            return;
        }
    }
    finishSignIn(sessionRecord);
}
Also used : EmailLinkPersistenceManager(com.firebase.ui.auth.util.data.EmailLinkPersistenceManager) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) EmailLinkParser(com.firebase.ui.auth.util.data.EmailLinkParser) SessionRecord(com.firebase.ui.auth.util.data.EmailLinkPersistenceManager.SessionRecord)

Example 4 with SessionRecord

use of com.firebase.ui.auth.util.data.EmailLinkPersistenceManager.SessionRecord in project FirebaseUI-Android by firebase.

the class EmailLinkPersistanceManagerTest method testSaveAndRetrieveIdpResonseForLinking_saveEmailFirst.

@Test
public void testSaveAndRetrieveIdpResonseForLinking_saveEmailFirst() {
    IdpResponse response = buildIdpResponse();
    mPersistenceManager.saveEmail(ApplicationProvider.getApplicationContext(), TestConstants.EMAIL, TestConstants.SESSION_ID, TestConstants.UID);
    mPersistenceManager.saveIdpResponseForLinking(ApplicationProvider.getApplicationContext(), response);
    SessionRecord sessionRecord = mPersistenceManager.retrieveSessionRecord(ApplicationProvider.getApplicationContext());
    assertThat(sessionRecord.getEmail()).isEqualTo(TestConstants.EMAIL);
    assertThat(sessionRecord.getSessionId()).isEqualTo(TestConstants.SESSION_ID);
    assertThat(sessionRecord.getAnonymousUserId()).isEqualTo(TestConstants.UID);
    assertThat(sessionRecord.getIdpResponseForLinking()).isEqualTo(response);
}
Also used : IdpResponse(com.firebase.ui.auth.IdpResponse) SessionRecord(com.firebase.ui.auth.util.data.EmailLinkPersistenceManager.SessionRecord) Test(org.junit.Test)

Aggregations

SessionRecord (com.firebase.ui.auth.util.data.EmailLinkPersistenceManager.SessionRecord)4 Test (org.junit.Test)3 IdpResponse (com.firebase.ui.auth.IdpResponse)2 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)1 EmailLinkParser (com.firebase.ui.auth.util.data.EmailLinkParser)1 EmailLinkPersistenceManager (com.firebase.ui.auth.util.data.EmailLinkPersistenceManager)1