-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(AuthUIConfiguration): implement configuration model, DSL builder and tests #2216
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a62097d
feat(AuthUIConfiguration): implement configuration model, DSL builder…
demolaf bf7c10b
Merge branch 'version-10.0.0-dev' of https://github.com/firebase/Fire…
demolaf 2c563bd
refactor: use OAuthProvider base class for common properties
demolaf 1ba20ae
feat: add Provider enum class for provider ids
demolaf 63c8e18
feat: setup default provider styles for each provider
demolaf a5a944a
test: added builder validation logic from old auth library and tests
demolaf 19787df
refactor: changes in API design docs
demolaf 7e010e4
test: fix AuthUIConfiguration constructor test
demolaf 4c9cc5e
Merge branch 'version-10.0.0-dev' of github.com:demolaf/FirebaseUI-An…
demolaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
357 changes: 357 additions & 0 deletions
357
auth/src/main/java/com/firebase/ui/auth/compose/configuration/AuthProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,357 @@ | ||
/* | ||
* Copyright 2025 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.firebase.ui.auth.compose.configuration | ||
|
||
import android.graphics.Color | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import com.google.firebase.auth.ActionCodeSettings | ||
import com.google.firebase.auth.EmailAuthProvider | ||
import com.google.firebase.auth.FacebookAuthProvider | ||
import com.google.firebase.auth.GithubAuthProvider | ||
import com.google.firebase.auth.GoogleAuthProvider | ||
import com.google.firebase.auth.PhoneAuthProvider | ||
import com.google.firebase.auth.TwitterAuthProvider | ||
|
||
@AuthUIConfigurationDsl | ||
class AuthProvidersBuilder { | ||
private val providers = mutableListOf<AuthProvider>() | ||
|
||
fun provider(provider: AuthProvider) { | ||
providers.add(provider) | ||
} | ||
|
||
internal fun build(): List<AuthProvider> = providers.toList() | ||
} | ||
|
||
/** | ||
* Enum class to represent all possible providers. | ||
*/ | ||
internal enum class Provider(val id: String) { | ||
GOOGLE(GoogleAuthProvider.PROVIDER_ID), | ||
FACEBOOK(FacebookAuthProvider.PROVIDER_ID), | ||
TWITTER(TwitterAuthProvider.PROVIDER_ID), | ||
GITHUB(GithubAuthProvider.PROVIDER_ID), | ||
EMAIL(EmailAuthProvider.PROVIDER_ID), | ||
PHONE(PhoneAuthProvider.PROVIDER_ID), | ||
ANONYMOUS("anonymous"), | ||
MICROSOFT("microsoft.com"), | ||
YAHOO("yahoo.com"), | ||
APPLE("apple.com"), | ||
} | ||
|
||
/** | ||
* Base abstract class for OAuth authentication providers with common properties. | ||
*/ | ||
abstract class OAuthProvider( | ||
override val providerId: String, | ||
open val scopes: List<String> = emptyList(), | ||
open val customParameters: Map<String, String> = emptyMap() | ||
) : AuthProvider(providerId) | ||
|
||
/** | ||
* Base abstract class for authentication providers. | ||
*/ | ||
abstract class AuthProvider(open val providerId: String) { | ||
/** | ||
* Email/Password authentication provider configuration. | ||
*/ | ||
class Email( | ||
/** | ||
* Requires the user to provide a display name. Defaults to true. | ||
*/ | ||
val isDisplayNameRequired: Boolean = true, | ||
|
||
/** | ||
* Enables email link sign-in, Defaults to false. | ||
*/ | ||
val isEmailLinkSignInEnabled: Boolean = false, | ||
|
||
/** | ||
* Settings for email link actions. | ||
*/ | ||
val actionCodeSettings: ActionCodeSettings?, | ||
|
||
/** | ||
* Allows new accounts to be created. Defaults to true. | ||
*/ | ||
val isNewAccountsAllowed: Boolean = true, | ||
|
||
/** | ||
* The minimum length for a password. Defaults to 6. | ||
*/ | ||
val minimumPasswordLength: Int = 6, | ||
|
||
/** | ||
* A list of custom password validation rules. | ||
*/ | ||
val passwordValidationRules: List<PasswordRule> | ||
) : AuthProvider(providerId = Provider.EMAIL.id) { | ||
fun validate() { | ||
if (isEmailLinkSignInEnabled) { | ||
val actionCodeSettings = actionCodeSettings | ||
?: requireNotNull(actionCodeSettings) { | ||
"ActionCodeSettings cannot be null when using " + | ||
"email link sign in." | ||
} | ||
|
||
check(actionCodeSettings.canHandleCodeInApp()) { | ||
"You must set canHandleCodeInApp in your " + | ||
"ActionCodeSettings to true for Email-Link Sign-in." | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Phone number authentication provider configuration. | ||
*/ | ||
class Phone( | ||
/** | ||
* The default country code to pre-select. | ||
*/ | ||
val defaultCountryCode: String?, | ||
|
||
/** | ||
* A list of allowed country codes. | ||
*/ | ||
val allowedCountries: List<String>?, | ||
|
||
/** | ||
* The expected length of the SMS verification code. Defaults to 6. | ||
*/ | ||
val smsCodeLength: Int = 6, | ||
|
||
/** | ||
* The timeout in seconds for receiving the SMS. Defaults to 60L. | ||
*/ | ||
val timeout: Long = 60L, | ||
|
||
/** | ||
* Enables instant verification of the phone number. Defaults to true. | ||
*/ | ||
val isInstantVerificationEnabled: Boolean = true, | ||
|
||
/** | ||
* Enables automatic retrieval of the SMS code. Defaults to true. | ||
*/ | ||
val isAutoRetrievalEnabled: Boolean = true | ||
) : AuthProvider(providerId = Provider.PHONE.id) | ||
|
||
/** | ||
* Google Sign-In provider configuration. | ||
*/ | ||
class Google( | ||
/** | ||
* The list of scopes to request. | ||
*/ | ||
override val scopes: List<String>, | ||
|
||
/** | ||
* The OAuth 2.0 client ID for your server. | ||
*/ | ||
val serverClientId: String?, | ||
|
||
/** | ||
* Requests an ID token. Default to true. | ||
*/ | ||
val requestIdToken: Boolean = true, | ||
|
||
/** | ||
* Requests the user's profile information. Defaults to true. | ||
*/ | ||
val requestProfile: Boolean = true, | ||
|
||
/** | ||
* Requests the user's email address. Defaults to true. | ||
*/ | ||
val requestEmail: Boolean = true, | ||
|
||
/** | ||
* A map of custom OAuth parameters. | ||
*/ | ||
override val customParameters: Map<String, String> = emptyMap() | ||
) : OAuthProvider( | ||
providerId = Provider.GOOGLE.id, | ||
scopes = scopes, | ||
customParameters = customParameters | ||
) | ||
|
||
/** | ||
* Facebook Login provider configuration. | ||
*/ | ||
class Facebook( | ||
/** | ||
* The list of scopes (permissions) to request. Defaults to email and public_profile. | ||
*/ | ||
override val scopes: List<String> = listOf("email", "public_profile"), | ||
|
||
/** | ||
* if true, enable limited login mode. Defaults to false. | ||
*/ | ||
val limitedLogin: Boolean = false, | ||
|
||
/** | ||
* A map of custom OAuth parameters. | ||
*/ | ||
override val customParameters: Map<String, String> = emptyMap() | ||
) : OAuthProvider( | ||
providerId = Provider.FACEBOOK.id, | ||
scopes = scopes, | ||
customParameters = customParameters | ||
) | ||
|
||
/** | ||
* Twitter/X authentication provider configuration. | ||
*/ | ||
class Twitter( | ||
/** | ||
* A map of custom OAuth parameters. | ||
*/ | ||
override val customParameters: Map<String, String> | ||
) : OAuthProvider( | ||
providerId = Provider.TWITTER.id, | ||
customParameters = customParameters | ||
) | ||
|
||
/** | ||
* Github authentication provider configuration. | ||
*/ | ||
class Github( | ||
/** | ||
* The list of scopes to request. Defaults to user:email. | ||
*/ | ||
override val scopes: List<String> = listOf("user:email"), | ||
|
||
/** | ||
* A map of custom OAuth parameters. | ||
*/ | ||
override val customParameters: Map<String, String> | ||
) : OAuthProvider( | ||
providerId = Provider.GITHUB.id, | ||
scopes = scopes, | ||
customParameters = customParameters | ||
) | ||
|
||
/** | ||
* Microsoft authentication provider configuration. | ||
*/ | ||
class Microsoft( | ||
/** | ||
* The list of scopes to request. Defaults to openid, profile, email. | ||
*/ | ||
override val scopes: List<String> = listOf("openid", "profile", "email"), | ||
|
||
/** | ||
* The tenant ID for Azure Active Directory. | ||
*/ | ||
val tenant: String?, | ||
|
||
/** | ||
* A map of custom OAuth parameters. | ||
*/ | ||
override val customParameters: Map<String, String> | ||
) : OAuthProvider( | ||
providerId = Provider.MICROSOFT.id, | ||
scopes = scopes, | ||
customParameters = customParameters | ||
) | ||
|
||
/** | ||
* Yahoo authentication provider configuration. | ||
*/ | ||
class Yahoo( | ||
/** | ||
* The list of scopes to request. Defaults to openid, profile, email. | ||
*/ | ||
override val scopes: List<String> = listOf("openid", "profile", "email"), | ||
|
||
/** | ||
* A map of custom OAuth parameters. | ||
*/ | ||
override val customParameters: Map<String, String> | ||
) : OAuthProvider( | ||
providerId = Provider.YAHOO.id, | ||
scopes = scopes, | ||
customParameters = customParameters | ||
) | ||
|
||
/** | ||
* Apple Sign-In provider configuration. | ||
*/ | ||
class Apple( | ||
/** | ||
* The list of scopes to request. Defaults to name and email. | ||
*/ | ||
override val scopes: List<String> = listOf("name", "email"), | ||
|
||
/** | ||
* The locale for the sign-in page. | ||
*/ | ||
val locale: String?, | ||
|
||
/** | ||
* A map of custom OAuth parameters. | ||
*/ | ||
override val customParameters: Map<String, String> | ||
) : OAuthProvider( | ||
providerId = Provider.APPLE.id, | ||
scopes = scopes, | ||
customParameters = customParameters | ||
) | ||
|
||
/** | ||
* Anonymous authentication provider. It has no configurable properties. | ||
*/ | ||
object Anonymous : AuthProvider(providerId = Provider.ANONYMOUS.id) | ||
|
||
/** | ||
* A generic OAuth provider for any unsupported provider. | ||
*/ | ||
class GenericOAuth( | ||
/** | ||
* The provider ID as configured in the Firebase console. | ||
*/ | ||
override val providerId: String, | ||
|
||
/** | ||
* The list of scopes to request. | ||
*/ | ||
override val scopes: List<String>, | ||
|
||
/** | ||
* A map of custom OAuth parameters. | ||
*/ | ||
override val customParameters: Map<String, String>, | ||
|
||
/** | ||
* The text to display on the provider button. | ||
*/ | ||
val buttonLabel: String, | ||
|
||
/** | ||
* An optional icon for the provider button. | ||
*/ | ||
val buttonIcon: ImageVector?, | ||
|
||
/** | ||
* An optional background color for the provider button. | ||
*/ | ||
val buttonColor: Color? | ||
) : OAuthProvider( | ||
providerId = providerId, | ||
scopes = scopes, | ||
customParameters = customParameters | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this verified against what we get from Firebase by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got this from the API Design docs, is there somewhere else I could check this from?