Skip to content

Commit fe76ec8

Browse files
lsiracsamtstern
authored andcommitted
Support for Generic OAuth Providers (initial support for Microsoft, Yahoo, and Apple) (#1705)
1 parent b0afc7e commit fe76ec8

File tree

55 files changed

+1643
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1643
-80
lines changed

app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public class AuthUiActivity extends AppCompatActivity {
7676
@BindView(R.id.email_link_provider) CheckBox mUseEmailLinkProvider;
7777
@BindView(R.id.phone_provider) CheckBox mUsePhoneProvider;
7878
@BindView(R.id.anonymous_provider) CheckBox mUseAnonymousProvider;
79+
@BindView(R.id.apple_provider) CheckBox mUseAppleProvider;
80+
@BindView(R.id.microsoft_provider) CheckBox mUseMicrosoftProvider;
81+
@BindView(R.id.yahoo_provider) CheckBox mUseYahooProvider;
7982

8083
@BindView(R.id.default_layout) RadioButton mDefaultLayout;
8184
@BindView(R.id.custom_layout) RadioButton mCustomLayout;
@@ -182,6 +185,8 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
182185
mUseEmailLinkProvider.setChecked(false);
183186
mUsePhoneProvider.setChecked(false);
184187
mUseAnonymousProvider.setChecked(false);
188+
mUseYahooProvider.setChecked(false);
189+
mUseAppleProvider.setChecked(false);
185190
}
186191
}
187192
});
@@ -421,6 +426,18 @@ private List<IdpConfig> getSelectedProviders() {
421426
selectedProviders.add(new IdpConfig.AnonymousBuilder().build());
422427
}
423428

429+
if (mUseMicrosoftProvider.isChecked()) {
430+
selectedProviders.add(new IdpConfig.MicrosoftBuilder().build());
431+
}
432+
433+
if (mUseYahooProvider.isChecked()) {
434+
selectedProviders.add(new IdpConfig.YahooBuilder().build());
435+
}
436+
437+
if (mUseAppleProvider.isChecked()) {
438+
selectedProviders.add(new IdpConfig.AppleBuilder().build());
439+
}
440+
424441
return selectedProviders;
425442
}
426443

app/src/main/java/com/firebase/uidemo/auth/SignedInActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ private void populateProfile(@Nullable IdpResponse response) {
192192
// Ignore this provider, it's not very meaningful
193193
break;
194194
default:
195-
throw new IllegalStateException(
196-
"Unknown provider: " + info.getProviderId());
195+
providers.add(info.getProviderId());
197196
}
198197
}
199198
}

app/src/main/java/com/firebase/uidemo/util/ConfigurationUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public static List<AuthUI.IdpConfig> getConfiguredProviders(@NonNull Context con
6767

6868

6969
providers.add(new AuthUI.IdpConfig.PhoneBuilder().build());
70-
70+
providers.add(new AuthUI.IdpConfig.MicrosoftBuilder().build());
71+
providers.add(new AuthUI.IdpConfig.YahooBuilder().build());
7172

7273
return providers;
7374
}

app/src/main/res/layout/auth_ui_layout.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,27 @@
102102
android:checked="true"
103103
android:text="@string/providers_anonymous" />
104104

105+
<CheckBox
106+
android:id="@+id/apple_provider"
107+
android:layout_width="wrap_content"
108+
android:layout_height="wrap_content"
109+
android:checked="true"
110+
android:text="@string/providers_apple" />
111+
112+
<CheckBox
113+
android:id="@+id/microsoft_provider"
114+
android:layout_width="wrap_content"
115+
android:layout_height="wrap_content"
116+
android:checked="true"
117+
android:text="@string/providers_microsoft" />
118+
119+
<CheckBox
120+
android:id="@+id/yahoo_provider"
121+
android:layout_width="wrap_content"
122+
android:layout_height="wrap_content"
123+
android:checked="true"
124+
android:text="@string/providers_yahoo" />
125+
105126
<TextView
106127
style="@style/Base.TextAppearance.AppCompat.Subhead"
107128
android:layout_width="wrap_content"

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<string name="providers_email_link">Email link</string>
3131
<string name="providers_phone">Phone</string>
3232
<string name="providers_anonymous">Anonymous</string>
33+
<string name="providers_apple">Apple</string>
34+
<string name="providers_microsoft">Microsoft</string>
35+
<string name="providers_yahoo">Yahoo</string>
3336

3437
<string name="layout_header">Layout</string>
3538
<string name="layout_default">Default</string>

auth-github/src/main/java/com/firebase/ui/auth/data/remote/GitHubSignInHandler.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.firebase.ui.auth.util.ExtraConstants;
2121
import com.firebase.ui.auth.viewmodel.ProviderSignInBase;
2222
import com.firebase.ui.auth.viewmodel.RequestCodes;
23+
import com.google.firebase.auth.FirebaseAuth;
2324
import com.google.firebase.auth.GithubAuthProvider;
2425

2526
import java.util.ArrayList;
@@ -183,4 +184,11 @@ private interface GitHubApi {
183184
@GET("user")
184185
Call<GitHubProfile> getUser(@Header("Authorization") String token);
185186
}
187+
188+
@Override
189+
public void startSignIn(@NonNull FirebaseAuth auth,
190+
@NonNull HelperActivityBase activity,
191+
@NonNull String providerId) {
192+
startSignIn(activity);
193+
}
186194
}

auth/README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ for more information.
9797

9898
### Identity provider configuration
9999

100-
In order to use either Google, Facebook or Twitter accounts with your app, ensure that
101-
these authentication methods are first configured in the Firebase console.
100+
In order to use either Google, Facebook, Twitter, Microsoft, Apple, or Yahoo accounts with your
101+
app, ensure that these authentication methods are first configured in the Firebase console.
102102

103103
#### Google
104104

@@ -148,6 +148,34 @@ allprojects {
148148
}
149149
```
150150

151+
#### Microsoft, Apple, and Yahoo
152+
153+
No FirebaseUI configuration is required for these providers.
154+
155+
We support the use of scopes and custom parameters for these providers. For example:
156+
157+
```java
158+
List<String> scopes =
159+
new ArrayList<String>() {
160+
{
161+
add("mail.read");
162+
add("calendars.read");
163+
}
164+
};
165+
166+
Map<String, String> customParams = new HashMap<>();
167+
customParams.put("tenant", "TENANT_ID");
168+
169+
IdpConfig microsoftConfig = new IdpConfig.MicrosoftBuilder()
170+
.setScopes(scopes)
171+
.setCustomParameters(customParams)
172+
.build();
173+
selectedProviders.add(microsoftConfig);
174+
```
175+
176+
Note: unlike other sign-in methods, signing in with these providers involves the use of a
177+
[Custom Chrome Tab](https://developer.chrome.com/multidevice/android/customtabs).
178+
151179
#### GitHub
152180

153181
We do not currently support Github as a sign-in method in FirebaseUI on Android. The current
@@ -236,6 +264,9 @@ startActivityForResult(
236264
new AuthUI.IdpConfig.GoogleBuilder().build(),
237265
new AuthUI.IdpConfig.FacebookBuilder().build(),
238266
new AuthUI.IdpConfig.TwitterBuilder().build(),
267+
new AuthUI.IdpConfig.MicrosoftBuilder().build(),
268+
new AuthUI.IdpConfig.YahooBuilder().build(),
269+
new AuthUI.IdpConfig.AppleBuilder().build(),
239270
new AuthUI.IdpConfig.EmailBuilder().build(),
240271
new AuthUI.IdpConfig.PhoneBuilder().build(),
241272
new AuthUI.IdpConfig.AnonymousBuilder().build()))

auth/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ android {
1313
disable("UnknownNullness") // TODO fix in future PR
1414
disable("TypographyQuotes") // Straight versus directional quotes
1515
disable("DuplicateStrings")
16+
disable("MissingTranslation") // TODO add translations
17+
disable("LocaleFolder")
18+
disable("IconLocation")
19+
disable("VectorPath")
1620
}
1721

1822
testOptions {

auth/src/main/java/com/firebase/ui/auth/AuthMethodPickerLayout.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,24 @@ public AuthMethodPickerLayout.Builder setAnonymousButtonId(@IdRes int anonymousB
158158
return this;
159159
}
160160

161+
public AuthMethodPickerLayout.Builder setMicrosoftButtonId(
162+
@IdRes int microsoftButtonId) {
163+
providersMapping.put(AuthUI.MICROSOFT_PROVIDER, microsoftButtonId);
164+
return this;
165+
}
166+
167+
public AuthMethodPickerLayout.Builder setAppleButtonId(
168+
@IdRes int appleButtonId) {
169+
providersMapping.put(AuthUI.APPLE_PROVIDER, appleButtonId);
170+
return this;
171+
}
172+
173+
public AuthMethodPickerLayout.Builder setYahooButtonId(
174+
@IdRes int yahooButtonId) {
175+
providersMapping.put(AuthUI.YAHOO_PROVIDER, yahooButtonId);
176+
return this;
177+
}
178+
161179
/**
162180
* Set the ID of a TextView where terms of service and privacy policy should be
163181
* displayed.
@@ -173,7 +191,8 @@ public AuthMethodPickerLayout build() {
173191
}
174192

175193
for (String key : providersMapping.keySet()) {
176-
if (!AuthUI.SUPPORTED_PROVIDERS.contains(key)) {
194+
if (!AuthUI.SUPPORTED_PROVIDERS.contains(key)
195+
&& !AuthUI.SUPPORTED_OAUTH_PROVIDERS.contains(key)) {
177196
throw new IllegalArgumentException("Unknown provider: " + key);
178197
}
179198
}

0 commit comments

Comments
 (0)