Search in sources :

Example 1 with EmailLinkParser

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

the class EmailLinkCrossDeviceLinkingFragment method onViewCreated.

@SuppressWarnings("WrongConstant")
@Override
@SuppressLint("WrongConstant")
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    mProgressBar = view.findViewById(R.id.top_progress_bar);
    mContinueButton = view.findViewById(R.id.button_continue);
    mContinueButton.setOnClickListener(this);
    String link = getFlowParams().emailLink;
    EmailLinkParser parser = new EmailLinkParser(link);
    String providerId = parser.getProviderId();
    String providerName = ProviderUtils.providerIdToProviderName(providerId);
    TextView body = view.findViewById(R.id.cross_device_linking_body);
    String bodyText = getString(R.string.fui_email_link_cross_device_linking_text, providerName);
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(bodyText);
    TextHelper.boldAllOccurencesOfText(spannableStringBuilder, bodyText, providerName);
    body.setText(spannableStringBuilder);
    // Justifies the text
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        body.setJustificationMode(android.text.Layout.JUSTIFICATION_MODE_INTER_WORD);
    }
    TextView footerText = view.findViewById(R.id.email_footer_tos_and_pp_text);
    PrivacyDisclosureUtils.setupTermsOfServiceFooter(requireContext(), getFlowParams(), footerText);
}
Also used : TextView(android.widget.TextView) EmailLinkParser(com.firebase.ui.auth.util.data.EmailLinkParser) SpannableStringBuilder(android.text.SpannableStringBuilder) SuppressLint(android.annotation.SuppressLint)

Example 2 with EmailLinkParser

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

the class EmailLinkSendEmailHandlerTest method validateSessionIdAddedToContinueUrl.

private void validateSessionIdAddedToContinueUrl(ActionCodeSettings actionCodeSettings, String providerId, boolean forceSameDevice) {
    EmailLinkParser parser = new EmailLinkParser(actionCodeSettings.getUrl());
    assertThat(parser.getSessionId()).isNotNull();
    assertThat(parser.getForceSameDeviceBit()).isEqualTo(forceSameDevice);
    assertThat(parser.getProviderId()).isEqualTo(providerId);
}
Also used : EmailLinkParser(com.firebase.ui.auth.util.data.EmailLinkParser)

Example 3 with EmailLinkParser

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

the class ContinueUrlBuilderTest method testAppendParams_encodedLink_expectSuccess.

@Test
public void testAppendParams_encodedLink_expectSuccess() {
    String continueUrlBuilder = new ContinueUrlBuilder(ENCODED_EMAIL_LINK).appendSessionId(SESSION_ID).appendAnonymousUserId(ANONYMOUS_USER_ID).appendProviderId(PROVIDER_ID).appendForceSameDeviceBit(FORCE_SAME_DEVICE).build();
    EmailLinkParser parser = new EmailLinkParser(continueUrlBuilder);
    assertThat(parser.getSessionId()).isEqualTo(SESSION_ID);
    assertThat(parser.getAnonymousUserId()).isEqualTo(ANONYMOUS_USER_ID);
    assertThat(parser.getProviderId()).isEqualTo(PROVIDER_ID);
    assertThat(parser.getForceSameDeviceBit()).isEqualTo(FORCE_SAME_DEVICE);
}
Also used : ContinueUrlBuilder(com.firebase.ui.auth.util.data.ContinueUrlBuilder) EmailLinkParser(com.firebase.ui.auth.util.data.EmailLinkParser) Test(org.junit.Test)

Example 4 with EmailLinkParser

use of com.firebase.ui.auth.util.data.EmailLinkParser 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 5 with EmailLinkParser

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

the class EmailLinkParserTest method testGetters_decodedLink.

@Test
public void testGetters_decodedLink() {
    EmailLinkParser parser = new EmailLinkParser(DECODED_EMAIL_LINK);
    assertThat(parser.getOobCode()).isEqualTo(OOB_CODE);
    assertThat(parser.getSessionId()).isEqualTo(SESSION_ID);
    assertThat(parser.getAnonymousUserId()).isEqualTo(ANONYMOUS_USER_ID);
    assertThat(parser.getProviderId()).isEqualTo(PROVIDER_ID);
    assertThat(parser.getForceSameDeviceBit()).isEqualTo(FORCE_SAME_DEVICE);
}
Also used : EmailLinkParser(com.firebase.ui.auth.util.data.EmailLinkParser) Test(org.junit.Test)

Aggregations

EmailLinkParser (com.firebase.ui.auth.util.data.EmailLinkParser)8 Test (org.junit.Test)5 ContinueUrlBuilder (com.firebase.ui.auth.util.data.ContinueUrlBuilder)2 SuppressLint (android.annotation.SuppressLint)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextView (android.widget.TextView)1 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)1 EmailLinkPersistenceManager (com.firebase.ui.auth.util.data.EmailLinkPersistenceManager)1 SessionRecord (com.firebase.ui.auth.util.data.EmailLinkPersistenceManager.SessionRecord)1