【问题标题】:Firebase custom token authentication callback not called未调用 Firebase 自定义令牌身份验证回调
【发布时间】:2017-10-01 18:23:58
【问题描述】:

我尝试使用 Digits 进行身份验证(短信/电话验证),然后在 success() 上的回调中调用 Firebase 自定义令牌身份验证。很好,Digits 工作 -> Firebase 发送身份验证并实际登录用户,但不调用 Firebase onComplete() 的回调。如果我直接调用 signInWithCustomToken() 而不通过 Digits,它会正常工作,onComplete() 它会被调用。问题可能是什么? 这是我的 onCreate() 中的内容:

    AuthConfig.Builder builder = new AuthConfig.Builder();
    builder.withAuthCallBack(new AuthCallback() {
        @Override
        public void success(DigitsSession session, String phoneNumber) {
            signInWithCustomToken();
        }

        @Override
        public void failure(DigitsException exception) {
        }
    });

    authConfigDigits = builder.build();

    Button digitsButton = (Button) findViewById(R.id.auth_button);
    digitsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Digits.authenticate(authConfigDigits);
        }
    });

然后我有自定义令牌身份验证方法 signInWithCustomToken() 本身:

private void signInWithCustomToken() {

    String customToken = "eyJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJodHRwczovL2lkZW50aXR5dG9vbGtpdC5nb29nbGVhcGlzLmNvbS9nb29nbGUuaWRlbnRpdHkuaWRlbnRpdHl0b29sa2l0LnYxLklkZW50aXR5VG9vbGtpdCIsImV4cCI6MTQ5Mzg0MDU5MiwiaWF0IjoxNDkzODM2OTkyLCJpc3MiOiJmaXJlYmFzZS1hZG1pbnNkay0xOXBqY0Btb3ZlY2VudHJhbC0zOGUzYS5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsInN1YiI6ImZpcmViYXNlLWFkbWluc2RrLTE5cGpjQG1vdmVjZW50cmFsLTM4ZTNhLmlhbS5nc2VydmljZWFjY291bnQuY29tIiwidWlkIjoic29tZS11aWQifQ.QdyviQ8vMhpMF7VJP949PdjVBwqM4EbZGxJvhCQtsRloJdIc16FPBG_RrBp2wZivWC-z1TIx1yctdMVGsoDAk5ptp-HlNyp5n31DyfZriGgo8zbhWln4RGG4wGYb7hSxGpyvm4STOM9N7TBBKt4lCZFYdpHVbT2idhr0hipxKCC_Ubjhwbjsfxrj5h59GHSyAdjw_yigNBHEtvsUfdGfzwKn_EW5qm5OAA0icCiqjnvsvW5RkwWKo7kWxqZT87-BoHsf5JguFeLGs0Ow9lgxAS2mSuuvni5qiYdLZdOKhu204Ctsty1pyFYrAWwWdnSrTWJwdkBx9xPgsE5UlipkRQ";

    mFirebaseAuth.signInWithCustomToken(customToken)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        Log.e(TAG, "Task is successfull");
                        openMainActivity();
                    } else {
                        Log.e(TAG, "Task failed");
                    }
                }
            });
}

【问题讨论】:

    标签: android authentication firebase firebase-authentication


    【解决方案1】:

    我现在通过延迟 signInWithCustomToken() 的调用解决了这个问题。 我不确定为什么它不起作用,可能是某种竞争条件,但正在改变:

    @Override
        public void success(DigitsSession session, String phoneNumber) {
            signInWithCustomToken();
        }
    

    与:

     @Override
            public void success(DigitsSession session, String phoneNumber) {
                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //100ms delay
                        signInWithCustomToken();
                    }
                }, 100);
    
            }
    

    解决了这个问题。如果有人能解释原因,我将不胜感激。

    【讨论】:

      猜你喜欢
      • 2013-12-10
      • 2023-03-12
      • 2017-12-19
      • 1970-01-01
      • 2016-11-06
      • 2017-07-03
      • 2020-07-20
      • 1970-01-01
      • 2013-11-19
      相关资源
      最近更新 更多