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

Split GitHub provider out into its own module #1421

Merged
merged 10 commits into from
Aug 29, 2018
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
implementation(Config.Libs.Support.multidex)

implementation(project(":auth"))
implementation(project(":auth-github"))
implementation(project(":firestore"))
implementation(project(":database"))
implementation(project(":storage"))
Expand Down
9 changes: 9 additions & 0 deletions auth-github/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies {
compileOnly(project(":auth"))

implementation(Config.Libs.Support.appCompat)
implementation(Config.Libs.Support.customTabs)

implementation(Config.Libs.Misc.retrofit)
implementation(Config.Libs.Misc.retrofitGson)
}
35 changes: 35 additions & 0 deletions auth-github/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.firebase.ui.auth.github">

<application>

<activity
android:name=".GitHubLoginActivity"
android:label=""
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:launchMode="singleTop"
android:theme="@style/FirebaseUI.Transparent">

<intent-filter
android:autoVerify="true"
tools:ignore="UnusedAttribute">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="@string/firebase_web_host"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok two questions about this string:

  1. I see we have duplicate strings.xml entries for firebase_web_host in both auth/.../strings.xml and auth-github/.../strings.xml ... is there a reason it needs to exist outside of the GitHub module? I feel like we only use it there but could be forgetting something.
  2. Now that we're sure you want to use GitHub auth when you include the -github module, should we explode at runtime if this string is still equal to CHANGE-ME? I think that might be helpful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, both those birds were killed with the same stone in the original implementation 😁:

Preconditions.checkConfigured(getApplicationContext(),
"GitHub provider unconfigured. Make sure to add your client id and secret." +
" See the docs for more info:" +
" https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md#github",
R.string.firebase_web_host,

  1. We need firebase_web_host in the auth module to do that check
  2. We do that check 😂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh

android:path="/__/auth/handler"
android:scheme="https"
tools:ignore="AppLinksAutoVerifyWarning" />
</intent-filter>

</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.firebase.ui.auth.ui.provider;
package com.firebase.ui.auth.github;

import android.annotation.SuppressLint;
import android.content.Context;
Expand All @@ -10,8 +10,6 @@
import android.support.customtabs.CustomTabsIntent;
import android.support.v4.content.ContextCompat;

import com.firebase.ui.auth.R;
import com.firebase.ui.auth.data.remote.GitHubSignInHandler;
import com.firebase.ui.auth.ui.HelperActivityBase;
import com.firebase.ui.auth.util.ExtraConstants;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.firebase.ui.auth.data.remote;
package com.firebase.ui.auth.github;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in .github.data.remote just to be consistent?


import android.app.Application;
import android.content.Intent;
Expand All @@ -12,14 +12,12 @@
import com.firebase.ui.auth.ErrorCodes;
import com.firebase.ui.auth.FirebaseUiException;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.R;
import com.firebase.ui.auth.data.model.GitHubProfile;
import com.firebase.ui.auth.data.model.GitHubTokenResponse;
import com.firebase.ui.auth.data.model.Resource;
import com.firebase.ui.auth.data.model.User;
import com.firebase.ui.auth.data.model.UserCancellationException;
import com.firebase.ui.auth.github.model.GitHubProfile;
import com.firebase.ui.auth.github.model.GitHubTokenResponse;
import com.firebase.ui.auth.ui.HelperActivityBase;
import com.firebase.ui.auth.ui.provider.GitHubLoginActivity;
import com.firebase.ui.auth.util.ExtraConstants;
import com.firebase.ui.auth.viewmodel.ProviderSignInBase;
import com.firebase.ui.auth.viewmodel.RequestCodes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.firebase.ui.auth.data.model;
package com.firebase.ui.auth.github.model;

import android.net.Uri;
import android.support.annotation.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.firebase.ui.auth.data.model;
package com.firebase.ui.auth.github.model;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand Down
10 changes: 10 additions & 0 deletions auth-github/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Expect auth resources -->
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
<item name="colorPrimary" type="color" />
<item name="FirebaseUI.Transparent" type="style" />

<item name="firebase_web_host" type="string" />
<item name="github_client_id" type="string" />
<item name="github_client_secret" type="string" />
</resources>
2 changes: 1 addition & 1 deletion auth/auth-proguard.pro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Twitter and Facebook are optional
# 3P providers are optional
-dontwarn com.facebook.**
-dontwarn com.twitter.**
# Keep the class names used to check for availablility
Expand Down
7 changes: 0 additions & 7 deletions auth/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import com.android.build.gradle.internal.dsl.TestOptions

android {
Expand Down Expand Up @@ -34,14 +33,8 @@ dependencies {
api(Config.Libs.PlayServices.auth)

compileOnly(Config.Libs.Provider.facebook)
// Needed to override Facebook
implementation(Config.Libs.Support.cardView)
implementation(Config.Libs.Support.customTabs)
compileOnly(Config.Libs.Provider.twitter) { isTransitive = true }

implementation(Config.Libs.Misc.retrofit)
implementation(Config.Libs.Misc.retrofitGson)

testImplementation(Config.Libs.Test.junit)
testImplementation(Config.Libs.Test.truth)
testImplementation(Config.Libs.Test.mockito)
Expand Down
24 changes: 0 additions & 24 deletions auth/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,6 @@
android:exported="false"
android:theme="@style/FirebaseUI.Transparent" />

<activity
android:name=".ui.provider.GitHubLoginActivity"
android:label=""
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:launchMode="singleTop"
android:theme="@style/FirebaseUI.Transparent">

<intent-filter
android:autoVerify="true"
tools:ignore="UnusedAttribute">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="@string/firebase_web_host"
android:path="/__/auth/handler"
android:scheme="https"
tools:ignore="AppLinksAutoVerifyWarning" />
</intent-filter>

</activity>

<activity
android:name=".ui.email.RecoverPasswordActivity"
android:label="@string/fui_title_recover_password_activity"
Expand Down
6 changes: 6 additions & 0 deletions auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,12 @@ public static final class GitHubBuilder extends Builder {
public GitHubBuilder() {
//noinspection deprecation taking a hit for the backcompat team
super(GithubAuthProvider.PROVIDER_ID);
if (!ProviderAvailability.IS_GITHUB_AVAILABLE) {
throw new RuntimeException(
"GitHub provider cannot be configured " +
"without dependency. Did you forget to add " +
"'com.firebaseui:firebase-ui-auth-github:VERSION' dependency?");
}
Preconditions.checkConfigured(getApplicationContext(),
"GitHub provider unconfigured. Make sure to add your client id and secret." +
" See the docs for more info:" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.firebase.ui.auth.data.remote;

import android.support.annotation.RestrictTo;

import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.viewmodel.ProviderSignInBase;

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public final class GitHubSignInHandlerBridge {
public static final Class<ProviderSignInBase<AuthUI.IdpConfig>> HANDLER_CLASS;

static {
try {
//noinspection unchecked
HANDLER_CLASS = (Class<ProviderSignInBase<AuthUI.IdpConfig>>)
Class.forName("com.firebase.ui.auth.github.GitHubSignInHandler");
} catch (ClassNotFoundException e) {
throw new IllegalStateException(
"Check for availability with ProviderAvailability first.", e);
}
}

private GitHubSignInHandlerBridge() {
throw new AssertionError("No instance for you!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import com.firebase.ui.auth.data.remote.AnonymousSignInHandler;
import com.firebase.ui.auth.data.remote.EmailSignInHandler;
import com.firebase.ui.auth.data.remote.FacebookSignInHandler;
import com.firebase.ui.auth.data.remote.GitHubSignInHandler;
import com.firebase.ui.auth.data.remote.GitHubSignInHandlerBridge;
import com.firebase.ui.auth.data.remote.GoogleSignInHandler;
import com.firebase.ui.auth.data.remote.PhoneSignInHandler;
import com.firebase.ui.auth.data.remote.TwitterSignInHandler;
Expand Down Expand Up @@ -167,7 +167,8 @@ private void populateIdpList(List<IdpConfig> providerConfigs,
buttonLayout = R.layout.fui_idp_button_twitter;
break;
case GithubAuthProvider.PROVIDER_ID:
GitHubSignInHandler github = supplier.get(GitHubSignInHandler.class);
ProviderSignInBase<IdpConfig> github =
supplier.get(GitHubSignInHandlerBridge.HANDLER_CLASS);
github.init(idpConfig);
provider = github;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.firebase.ui.auth.data.model.FlowParameters;
import com.firebase.ui.auth.data.model.User;
import com.firebase.ui.auth.data.remote.FacebookSignInHandler;
import com.firebase.ui.auth.data.remote.GitHubSignInHandler;
import com.firebase.ui.auth.data.remote.GitHubSignInHandlerBridge;
import com.firebase.ui.auth.data.remote.GoogleSignInHandler;
import com.firebase.ui.auth.data.remote.TwitterSignInHandler;
import com.firebase.ui.auth.ui.InvisibleActivityBase;
Expand Down Expand Up @@ -77,7 +77,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mProvider = twitter;
break;
case GithubAuthProvider.PROVIDER_ID:
GitHubSignInHandler github = supplier.get(GitHubSignInHandler.class);
ProviderSignInBase<AuthUI.IdpConfig> github =
supplier.get(GitHubSignInHandlerBridge.HANDLER_CLASS);
github.init(providerConfig);
mProvider = github;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import com.firebase.ui.auth.data.model.FlowParameters;
import com.firebase.ui.auth.data.model.User;
import com.firebase.ui.auth.data.remote.FacebookSignInHandler;
import com.firebase.ui.auth.data.remote.GitHubSignInHandler;
import com.firebase.ui.auth.data.remote.GitHubSignInHandlerBridge;
import com.firebase.ui.auth.data.remote.GoogleSignInHandler;
import com.firebase.ui.auth.data.remote.TwitterSignInHandler;
import com.firebase.ui.auth.ui.AppCompatBase;
Expand Down Expand Up @@ -132,7 +132,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
providerName = R.string.fui_idp_name_twitter;
break;
case GithubAuthProvider.PROVIDER_ID:
GitHubSignInHandler github = supplier.get(GitHubSignInHandler.class);
ProviderSignInBase<AuthUI.IdpConfig> github =
supplier.get(GitHubSignInHandlerBridge.HANDLER_CLASS);
github.init(config);
mProvider = github;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public final class ProviderAvailability {
public static final boolean IS_GITHUB_AVAILABLE =
exists("com.firebase.ui.auth.github.GitHubSignInHandler");
public static final boolean IS_FACEBOOK_AVAILABLE =
exists("com.facebook.login.LoginManager");
public static final boolean IS_TWITTER_AVAILABLE =
Expand Down
33 changes: 1 addition & 32 deletions auth/src/main/res/values/config.xml
Original file line number Diff line number Diff line change
@@ -1,44 +1,13 @@
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
<!-- Example: project-id.firebaseapp.com. Used for OAuth redirects -->
<string name="default_web_client_id" translatable="false">CHANGE-ME</string>
<string name="firebase_web_host" translatable="false">CHANGE-ME</string>

<!--
The Facebook Application ID associated with this Android application. This
must be overridden by users of FirebaseUI auth in order to support Facebook
accounts in the authentication flow.

See:
https://developers.facebook.com/docs/facebook-login/android
-->
<string name="facebook_application_id" translatable="false">CHANGE-ME</string>

<!--
To enable Chrome Custom Tabs for Facebook Login on devices without the Facebook app
installed, change this value to your Facebook App ID prefixed with 'fb'. This should be
'fb' + the value of the facebook_application_id string above

See:
https://developers.facebook.com/docs/facebook-login/android#chrome_custom_tabs
-->
<string name="facebook_login_protocol_scheme" translatable="false">fbYOUR_APP_ID</string>

<!--
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to kill these comments?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our documentation in the config.xml is different in the auth vs app module, so I was trying to unify them. I've made it so auth is the documented one with app pointing to it. WDYT? Should it be flipped?

The Google web client ID associated with this Android application. The
google-services gradle plugin will automatically provide this value.

See:
https://developers.google.com/identity/sign-in/web/devconsole-project
https://developers.google.com/android/guides/google-services-plugin
-->
<string name="default_web_client_id" translatable="false">CHANGE-ME</string>

<!-- Your Twitter Consumer Key. -->
<string name="twitter_consumer_key" translatable="false">CHANGE-ME</string>
<!-- Your Twitter Consumer Secret. -->
<string name="twitter_consumer_secret" translatable="false">CHANGE-ME</string>

<!-- Your GitHub Client ID. -->
<string name="github_client_id" translatable="false">CHANGE-ME</string>
<!-- Your GitHub Client Secret. -->
<string name="github_client_secret" translatable="false">CHANGE-ME</string>
</resources>
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object Config {
const val version = "4.2.0-SNAPSHOT"
val submodules = listOf("auth", "common", "firestore", "database", "storage")
val submodules = listOf("auth", "auth-github", "common", "firestore", "database", "storage")

private const val kotlinVersion = "1.2.61"

Expand Down Expand Up @@ -30,6 +30,7 @@ object Config {
const val multidex = "com.android.support:multidex:1.0.3"
const val annotations = "com.android.support:support-annotations:$version"
const val v4 = "com.android.support:support-v4:$version"
const val appCompat = "com.android.support:appcompat-v7:$version"
const val design = "com.android.support:design:$version"
const val recyclerView = "com.android.support:recyclerview-v7:$version"
const val cardView = "com.android.support:cardview-v7:$version"
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include(
":app", ":library",

":auth",
":auth", ":auth-github",
":common", ":firestore", ":database",
":storage",

Expand Down