android - 谷歌搜索引擎优化选择器 - 使用另一个帐户选项不给回调

时间:2018-05-10 11:57:11

标签: android firebase google-api-client google-authentication

enter image description here

以下是重现问题的步骤:

  1. 点击谷歌登录按钮。
  2. 选择“使用其他帐户”
  3. 使用新帐户登录,这应该会将您带回应用程序。
  4. 应用程序仅显示黑暗叠加层和同意表单或回调(对onActivityResult)无效。
  5. 然后,如果我触摸屏幕,黑暗覆盖会消失,此时如果我再次按下谷歌按钮,它会自动使用该帐户登录。我尝试了一些应用程序,如stackoverflow,traveloka,airBNB,我自己的简单应用程序,谷歌SSO按钮和glassdoor,lazada等等,所有这些都在得到选项3后出错。

    我想也许是[oauth同意书]: enter image description here

    我填写了它,但我只是请求电子邮件作为谷歌SSO选项。所以我填写表格,但等待一段时间后没有。

    如果你想查看我的完整代码,那就是标准的google SSO按钮and its here: 该类名为LoginFragment.kt

    但是让我在这里发布处理登录的课程:

        import android.content.Intent
    import android.os.Bundle
    import android.view.*
    import android.widget.Toast
    import com.github.ajalt.timberkt.Timber
    import com.google.android.gms.auth.api.Auth
    import com.google.android.gms.auth.api.signin.GoogleSignIn
    import com.google.android.gms.auth.api.signin.GoogleSignInAccount
    import com.google.android.gms.auth.api.signin.GoogleSignInOptions
    import com.google.android.gms.common.api.ApiException
    import com.google.android.gms.common.api.GoogleApiClient
    import com.google.firebase.auth.FirebaseAuth
    import com.google.firebase.auth.GoogleAuthProvider
    import example.org.weathermap.R
    import example.org.weathermap.frameworks.bus.events.LoginSuccessEvent
    import example.org.weathermap.presentation.view.application.WeatherApplication
    import example.org.weathermap.presentation.view.base.BaseMvpFragment
    import example.org.weathermap.presentation.contracts.authentication.AuthenticationView.LoginView
    import example.org.weathermap.presentation.presenters.weather.LoginPresenter
    import kotlinx.android.synthetic.main.login_fragment.*
    import org.greenrobot.eventbus.EventBus
    import javax.inject.Inject
    
    
    class LoginFragment : BaseMvpFragment<LoginView, LoginPresenter>(), LoginView {
    
        @Inject
        lateinit var mPresenter: LoginPresenter
    
        @Inject
        lateinit var mAuth: FirebaseAuth
    
        private var mGoogleApiClient: GoogleApiClient? = null
    
        @Inject
        lateinit var bus: EventBus
    
        override fun createPresenter(): LoginPresenter {
            return mPresenter
        }
    
        override fun onDestroyView() {
            super.onDestroyView()
            mGoogleApiClient?.let { client ->
                when (client.isConnected) {
                    true -> activity?.let {
                        client.stopAutoManage(it)
                        client.disconnect()
                    }
                    false -> {
                    }
                }
            }
        }
    
        override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
            val rootView = inflater.inflate(R.layout.login_fragment, container, false)
            (activity!!.applicationContext as WeatherApplication).appComponent.inject(this)
            setHasOptionsMenu(true)
            return rootView
        }
    
        override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
            super.onViewCreated(view, savedInstanceState)
            initView()
    
        }
    
        override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
            super.onCreateOptionsMenu(menu, inflater)
            menu?.clear()
        }
    
        private fun initView() {
            // Configure Google Sign In
            val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestIdToken(getString(R.string.default_web_client_id))
                    .requestEmail()
                    .build()
    
            activity?.let {
                mGoogleApiClient = GoogleApiClient.Builder(it).enableAutoManage(it, { Toast.makeText(activity, "login error", Toast.LENGTH_LONG).show() })
                        ?.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                        ?.build()
            }
            googleBtn.setOnClickListener { presenter.doSignIn() }
        }
    
        override fun signIn() {
            val signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient)
            startActivityForResult(signInIntent, RC_SIGN_IN)
        }
    
        companion object {
            const val RC_SIGN_IN = 1
            fun newInstance(b: Bundle?): LoginFragment {
                val frag = LoginFragment()
                frag.arguments = b ?: Bundle()
                return frag
            }
        }
    
        override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
            super.onActivityResult(requestCode, resultCode, data)
            if (requestCode == RC_SIGN_IN) {
                val task = GoogleSignIn.getSignedInAccountFromIntent(data)
                try {
                    // Google Sign In was successful, authenticate with Firebase
                    val account = task.getResult(ApiException::class.java)
                    presenter.doFirebaseAuthWithGoogle(account)
                } catch (e: ApiException) {
                    // Google Sign In failed, update UI appropriately
                    Timber.e { "Google sign in failed" }
                    Toast.makeText(activity, R.string.login_failed, Toast.LENGTH_LONG).show()
                }
    
            }
        }
    
        override fun firebaseAuthWithGoogle(acct: GoogleSignInAccount?) {
            showLoading(true)
            val credential = GoogleAuthProvider.getCredential(acct?.idToken, null)
            activity?.let {
                mAuth.signInWithCredential(credential)
                        .addOnCompleteListener(it, {
                            showLoading(false)
                            when (it.isSuccessful) {
                                true -> {
                                    bus.post(LoginSuccessEvent())
                                }
                                else -> {
                                    Toast.makeText(activity, getString(R.string.login_failed), Toast.LENGTH_LONG).show()
                                }
                            }
                        })
            }
        }
    }
    
    我在做错了什么?这是一个谷歌的bug吗?如果可能的话,我甚至会选择在选择器上禁用此选项的方法。

    我在api 24上完成的测试

1 个答案:

答案 0 :(得分:0)

来自firebase ui team - https://github.com/firebase/FirebaseUI-Android/issues/1297。我发现这是一个已知问题,将在下一个谷歌播放服务版本中修复。