首页 > 解决方案 > Firebase UI 电子邮件链接登录意图额外为空

问题描述

以下 3 个函数用于设置电子邮件和其他身份验证检查(按顺序调用)

    private void buildSignInIntentBuilder() {

        ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder()
                        .setAndroidPackageName(getString(R.string.packageName), true, null)
                        .setHandleCodeInApp(true)
                        .setUrl(getString(R.string.dynamic_link_url))
                        .build();

        List<AuthUI.IdpConfig> providers = Arrays.asList(
                new AuthUI.IdpConfig.EmailBuilder()
                        .enableEmailLinkSignIn()
                        .setActionCodeSettings(actionCodeSettings)
                        .build(),
                // new AuthUI.IdpConfig.EmailBuilder().setRequireName(false).build(),
                new AuthUI.IdpConfig.PhoneBuilder()
                        .build(),
                new AuthUI.IdpConfig.GoogleBuilder()
                        .build(),
                new AuthUI.IdpConfig.FacebookBuilder()
                        .build());

        signInIntentBuilder = AuthUI.getInstance()
                .createSignInIntentBuilder()
                .setIsSmartLockEnabled(false)
                .setAvailableProviders(providers)
                .setLogo(R.drawable.icon_forget_me_not_1);
    }

    private void catchEmailLinkSignIn() {
        Log.d(TAG, "Intent: " + getIntent().getExtras());
        if (AuthUI.canHandleIntent(getIntent())) {
            if (getIntent().getExtras() == null) {
                return;
            }

            String link = getIntent().getExtras().getString(ExtraConstants.EMAIL_LINK_SIGN_IN);
            Log.d(TAG, "link: " + link);
            if (link != null) {
                signInIntentBuilder.setEmailLink(link);
            }
        }
    }

    private void createCheckAndSigninListener() {
        // set firebase sign in listener
        mAuthStateListner = firebaseAuth -> {
            // Already logged in
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                Log.d(TAG, "user already signed in");
                // Check user even if signed in to register him to database (if haven't)
                FirebaseAuthHelper.getInstance().checkRegisterUser(user, this, CHECK_USER_DB);
            } else {
                Log.d(TAG, "user hasn't signed in");
                // Signed out or hasn't logged in
                startActivityForResult(
                        signInIntentBuilder
                                .build(),
                        RC_SIGN_IN
                );

            }
        };
    }

我已经建立了与 firebase 托管的动态链接。并且能够在单击收到的电子邮件链接后重定向到相同的活动。

然而,

String link = getIntent().getExtras().getString(ExtraConstants.EMAIL_LINK_SIGN_IN);
Log.d(TAG, "link: " + link); // --> produces "link: null"

显示尽管成功获得了意图,EMAIL_LINK_SIGNINgetExtras(). 我花了几个小时查看 FirebaseUi 的源代码,但我没有找到常量EMAIL_LINK_SIGN_IN的使用位置以及动态链接的意图是如何解析的。

任何想法如何解决这个问题表示赞赏。我已经花了一整天的时间试图弄清楚这一点。

标签: firebasefirebase-authenticationfirebaseui

解决方案


而不是使用String link = getIntent().getExtras().getString(ExtraConstants.EMAIL_LINK_SIGN_IN); usegetIntent().getData().toString();来代替。


推荐阅读