Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Developer error using Microsoft authentication provider #2166

Open
MartonPRez opened this issue Jul 24, 2024 · 1 comment
Open

Developer error using Microsoft authentication provider #2166

MartonPRez opened this issue Jul 24, 2024 · 1 comment

Comments

@MartonPRez
Copy link

MartonPRez commented Jul 24, 2024

Step 1: Are you in the right place?

  • For issues or feature requests related to the code in this repository file a GitHub issue.

Step 2: Describe your environment

  • Android device: SM-S918B/DS
  • Android OS version: 14
  • Google Play Services version: 24.26.32
  • Firebase/Play Services SDK version: 32.8.1
  • FirebaseUI version: 8.0.0

(Also tried multiple Firebase BOM versions between 28.0.0-32.8.1, tried FirebaseUI 7.2.2, and using an API 34 Play Services enabled emulator, same result)

Step 3: Describe the problem:

Getting com.firebase.ui.auth.FirebaseUiException: Developer error after going through authentication with Microsoft auth provider.

The error comes from ProviderUtils.java:229.
NOTE: My assumption is that this usecase happens, since the email I'm using [email protected] is already authenticated with Google as a provider.
The web AuthUI library handles this by asking giving the user the option to link the accounts. Is this what we don't have on Android, and if so, how do we handle this manually?

The setup in the firebase console, and the mobile client should be good, based on the facts that:

  1. Google authentication works on mobile as expected (suggesting the correct config is used)
  2. Microsoft authentication works for our webapp using the same project (suggesting the Firebase Console setup is correct)

Observed Results:

onActivityResult is called after the Custom Google Chrome tab is closed with resultCode=0, and info in data.extras:
IdpResponse{mUser=null, mToken='null', mSecret='null', mIsNewUser='false', mException=com.firebase.ui.auth.FirebaseUiException: Developer error, mPendingCredential=null}

Expected Results:

onActivityResult called with a successful resultCode=-1, authentication succeeds.

Relevant Code:

val intent = when (providerType) {
  LoginProviderType.GOOGLE -> viewModel.getGoogleLoginIntent(email)
  LoginProviderType.MICROSOFT -> viewModel.getMicrosoftLoginIntent(email)
  else -> return@observeFreshly
}
startActivityForResult(intent, REQUEST_CODE)

-----

override fun getMicrosoftLoginIntent(email: String?): Intent {
      val providerBuilder = AuthUI.IdpConfig.MicrosoftBuilder()
      if (!email.isNullOrBlank()) {
          providerBuilder.setCustomParameters(
              mapOf("login_hint" to email)
          )
      }
      return AuthUI.getInstance()
          .createSignInIntentBuilder()
          .setLogo(R.drawable.logo)
          .setTheme(R.style.MyStyle)
          .setAvailableProviders(arrayListOf(providerBuilder.build()))
          .setIsSmartLockEnabled(false)
          .build()
  }
  
----

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
      super.onActivityResult(requestCode, resultCode, data)
      if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
          viewModel.onLoginFlowDone()
      }
  }

@MartonPRez
Copy link
Author

I've figured out what is happening, but not closing the issue to see if there is any workaround for this usecase.

Since our application requires us to use to use email+password login with a given tenant, and any other authentication methods without a tenant, we can't use the complete UI solution this library provides.
Our workaround was to launch dedicated intents, one per auth provider.
This caused the error, since when the library tries to link two accounts from different providers, both providers needs to be set as allowedProviders, which is not the case our aforementioned setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant