firebase / FirebaseUI-Android

Optimized UI components for Firebase
https://firebaseopensource.com/projects/firebase/firebaseui-android/
Apache License 2.0
4.61k stars 1.83k forks source link

Feature request: Support any OpenID Connect Provider #2131

Open alex-kor opened 1 year ago

alex-kor commented 1 year ago

environment

the problem:

Making a connection to OIDC provider which is added through Firebase console App crashes when assembling list of Providers using provider builder: AuthUI.IdpConfig.GenericOAuthProviderBuilder("oidc.provider-id","provider-name", R.layout.oidc_button).build(),

Steps to reproduce:

  1. Create a Firebase project
  2. Add Authentication with Google
  3. Add OIDC provider as a sign in method
  4. On Android Platform try to create a list of providers using GenericOAuthProviderBuilder
  5. Observe the crash

Observed Results:

logcat: FATAL EXCEPTION: main Process: com.tmobile.authentication, PID: 9550 java.lang.IllegalArgumentException: Unknown provider: oidc.provider-id at com.firebase.ui.auth.AuthUI$IdpConfig$Builder.(AuthUI.java:635) at com.firebase.ui.auth.AuthUI$IdpConfig$GenericOAuthProviderBuilder.(AuthUI.java:1251)

Expected Results:

App should not crash and should open a dialog showing my OIDC provider in a list of sign-in buttons

Relevant Code:

  val providers = arrayListOf(
        AuthUI.IdpConfig.GoogleBuilder().build(),
        AuthUI.IdpConfig.GenericOAuthProviderBuilder("oidc.provider-id","provider-name", R.layout.oidc_button).build()
    )
    val signInIntent = AuthUI.getInstance()
        .createSignInIntentBuilder()
        .setAvailableProviders(providers)
        .build()
val firebaseSignInLauncher = rememberLauncherForActivityResult(
        contract = FirebaseAuthUIActivityResultContract(),
        onResult = {
            onFirebaseUiLogin(it.idpResponse)
        }
    )

... later in a code ...
firebaseSignInLauncher.launch(signInIntent)
alex-kor commented 1 year ago

Hi Rosario. Any updates on this issue? Do you have any possible ideas when you think you can fix it?

jhuleatt commented 1 year ago

Hi @alex-kor, GenericOAuthProviderBuilder is not a documented API, and is not currently meant to be used to implement custom OIDC providers. The parent constructor for GenericOAuthProviderBuilder explicitly checks that the ID provided is one that is intended to be used in FirebaseUI: https://github.com/firebase/FirebaseUI-Android/blob/5b6c9f01f5a674d754d8e9b1242197fe040086e7/auth/src/main/java/com/firebase/ui/auth/AuthUI.java#L632-L638

Supported providers are: https://github.com/firebase/FirebaseUI-Android/blob/5b6c9f01f5a674d754d8e9b1242197fe040086e7/auth/src/main/java/com/firebase/ui/auth/AuthUI.java#L118-L140

Adding the ability to set any OIDC provider sounds like a useful feature request, so I've added the feature request label to this issue. In the meantime you'll need to fork the library if you want to modify it to support a custom OIDC provider.