Skip to content

Add support for GitHub IDP #1199

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 27 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
375800a
Add support for GitHub IDP
SUPERCILEX Mar 25, 2018
3b986db
Merge remote-tracking branch 'upstream/version-3.3.0-dev' into github
SUPERCILEX Mar 26, 2018
caa8257
Fix merge mistakes
SUPERCILEX Mar 26, 2018
396c620
Fix more merge mistakes
SUPERCILEX Mar 26, 2018
dc8222b
Start cleanup and officialization now that the diff is reasonable
SUPERCILEX Mar 26, 2018
160996e
Add documentation
SUPERCILEX Mar 26, 2018
f0c5afe
Merge remote-tracking branch 'upstream/master' into github
SUPERCILEX Mar 28, 2018
e75ef82
Merge remote-tracking branch 'upstream/version-3.3.1-dev' into github
SUPERCILEX Apr 12, 2018
d90596f
Merge remote-tracking branch 'upstream/version-3.4.0-dev' into github
SUPERCILEX Apr 21, 2018
4600290
Yes! Our proguard build caught an error!
SUPERCILEX Apr 21, 2018
282f166
Merge remote-tracking branch 'upstream/version-4.0.0-dev' into github
SUPERCILEX May 5, 2018
c7ba0e0
Merge remote-tracking branch 'upstream/master' into github
SUPERCILEX May 29, 2018
c5278c6
Merge branch 'version-4.1.0-dev' into github
SUPERCILEX Jun 13, 2018
f082f09
Fix merge mistakes
SUPERCILEX Jun 13, 2018
178589d
Fix merge mistakes
SUPERCILEX Jun 13, 2018
cd27c48
Merge remote-tracking branch 'upstream/version-4.1.0-dev' into github
SUPERCILEX Jun 14, 2018
f4874a2
Address review feedback
SUPERCILEX Jun 15, 2018
b441a6b
Fix a few bugs related to process death
SUPERCILEX Jun 15, 2018
b672968
Finish object mapping
SUPERCILEX Jun 15, 2018
1363be4
Inline
SUPERCILEX Jun 15, 2018
e0f2982
Remove redirect URI hacks and add docs
SUPERCILEX Jun 15, 2018
49299d4
Tidy
SUPERCILEX Jun 15, 2018
7f73827
Fix tests
SUPERCILEX Jun 15, 2018
3722227
Fix lint
SUPERCILEX Jun 15, 2018
36cc5ec
Significant docs improvements
SUPERCILEX Jun 19, 2018
c1412a2
Add an "I'm stuck" section
SUPERCILEX Jun 19, 2018
ee30fe2
Remove possibly offensive language
SUPERCILEX Jun 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 77 additions & 23 deletions app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ public class AuthUiActivity extends AppCompatActivity {
@BindView(R.id.google_provider) CheckBox mUseGoogleProvider;
@BindView(R.id.facebook_provider) CheckBox mUseFacebookProvider;
@BindView(R.id.twitter_provider) CheckBox mUseTwitterProvider;
@BindView(R.id.github_provider) CheckBox mUseGitHubProvider;
@BindView(R.id.email_provider) CheckBox mUseEmailProvider;
@BindView(R.id.phone_provider) CheckBox mUsePhoneProvider;

@BindView(R.id.default_theme) RadioButton mUseDefaultTheme;
@BindView(R.id.green_theme) RadioButton mUseGreenTheme;
@BindView(R.id.purple_theme) RadioButton mUsePurpleTheme;
@BindView(R.id.dark_theme) RadioButton mUseDarkTheme;
@BindView(R.id.default_theme) RadioButton mDefaultTheme;
@BindView(R.id.green_theme) RadioButton mGreenTheme;
@BindView(R.id.purple_theme) RadioButton mPurpleTheme;
@BindView(R.id.dark_theme) RadioButton mDarkTheme;

@BindView(R.id.firebase_logo) RadioButton mFirebaseLogo;
@BindView(R.id.google_logo) RadioButton mGoogleLogo;
Expand All @@ -85,13 +86,17 @@ public class AuthUiActivity extends AppCompatActivity {
@BindView(R.id.google_privacy) RadioButton mUseGooglePrivacyPolicy;
@BindView(R.id.firebase_privacy) RadioButton mUseFirebasePrivacyPolicy;

@BindView(R.id.google_scopes_header) TextView mGoogleScopesLabel;
@BindView(R.id.google_scopes_header) TextView mGoogleScopesHeader;
@BindView(R.id.google_scope_drive_file) CheckBox mGoogleScopeDriveFile;
@BindView(R.id.google_scope_youtube_data) CheckBox mGoogleScopeYoutubeData;

@BindView(R.id.facebook_permissions_header) TextView mFacebookScopesLabel;
@BindView(R.id.facebook_permission_friends) CheckBox mFacebookScopeFriends;
@BindView(R.id.facebook_permission_photos) CheckBox mFacebookScopePhotos;
@BindView(R.id.facebook_permissions_header) TextView mFacebookPermissionsHeader;
@BindView(R.id.facebook_permission_friends) CheckBox mFacebookPermissionFriends;
@BindView(R.id.facebook_permission_photos) CheckBox mFacebookPermissionPhotos;

@BindView(R.id.github_permissions_header) TextView mGitHubPermissionsHeader;
@BindView(R.id.github_permission_repo) CheckBox mGitHubPermissionRepo;
@BindView(R.id.github_permission_gist) CheckBox mGitHubPermissionGist;

@BindView(R.id.credential_selector_enabled) CheckBox mEnableCredentialSelector;
@BindView(R.id.hint_selector_enabled) CheckBox mEnableHintSelector;
Expand Down Expand Up @@ -127,13 +132,13 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
mUseFacebookProvider.setChecked(false);
mUseFacebookProvider.setEnabled(false);
mUseFacebookProvider.setText(R.string.facebook_label_missing_config);
setFacebookScopesEnabled(false);
setFacebookPermissionsEnabled(false);
} else {
setFacebookScopesEnabled(mUseFacebookProvider.isChecked());
setFacebookPermissionsEnabled(mUseFacebookProvider.isChecked());
mUseFacebookProvider.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
setFacebookScopesEnabled(checked);
setFacebookPermissionsEnabled(checked);
}
});
}
Expand All @@ -144,12 +149,28 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
mUseTwitterProvider.setText(R.string.twitter_label_missing_config);
}

if (isGoogleMisconfigured() || isFacebookMisconfigured() || isTwitterMisconfigured()) {
if (isGitHubMisconfigured()) {
mUseGitHubProvider.setChecked(false);
mUseGitHubProvider.setEnabled(false);
mUseGitHubProvider.setText(R.string.github_label_missing_config);
setGitHubPermissionsEnabled(false);
} else {
setGitHubPermissionsEnabled(mUseGitHubProvider.isChecked());
mUseGitHubProvider.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
setGitHubPermissionsEnabled(checked);
}
});
}

if (isGoogleMisconfigured() || isFacebookMisconfigured()
|| isTwitterMisconfigured() || isGitHubMisconfigured()) {
showSnackbar(R.string.configuration_required);
}

if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
mUseDarkTheme.setChecked(true);
mDarkTheme.setChecked(true);
}
}

Expand Down Expand Up @@ -232,19 +253,19 @@ private void startSignedInActivity(IdpResponse response) {

@OnClick({R.id.default_theme, R.id.purple_theme, R.id.green_theme, R.id.dark_theme})
public void toggleDarkTheme() {
int mode = mUseDarkTheme.isChecked() ?
int mode = mDarkTheme.isChecked() ?
AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_AUTO;
AppCompatDelegate.setDefaultNightMode(mode);
getDelegate().setLocalNightMode(mode);
}

@StyleRes
private int getSelectedTheme() {
if (mUseGreenTheme.isChecked()) {
if (mGreenTheme.isChecked()) {
return R.style.GreenTheme;
}

if (mUsePurpleTheme.isChecked()) {
if (mPurpleTheme.isChecked()) {
return R.style.PurpleTheme;
}

Expand Down Expand Up @@ -279,6 +300,12 @@ private List<IdpConfig> getSelectedProviders() {
selectedProviders.add(new IdpConfig.TwitterBuilder().build());
}

if (mUseGitHubProvider.isChecked()) {
selectedProviders.add(new IdpConfig.GitHubBuilder()
.setPermissions(getGitHubPermissions())
.build());
}

if (mUseEmailProvider.isChecked()) {
selectedProviders.add(new IdpConfig.EmailBuilder()
.setRequireName(mRequireName.isChecked())
Expand Down Expand Up @@ -326,16 +353,32 @@ private boolean isTwitterMisconfigured() {
return twitterConfigs.contains(AuthUI.UNCONFIGURED_CONFIG_VALUE);
}

private boolean isGitHubMisconfigured() {
List<String> gitHubConfigs = Arrays.asList(
getString(R.string.firebase_web_host),
getString(R.string.github_client_id),
getString(R.string.github_client_secret)
);

return gitHubConfigs.contains(AuthUI.UNCONFIGURED_CONFIG_VALUE);
}

private void setGoogleScopesEnabled(boolean enabled) {
mGoogleScopesLabel.setEnabled(enabled);
mGoogleScopesHeader.setEnabled(enabled);
mGoogleScopeDriveFile.setEnabled(enabled);
mGoogleScopeYoutubeData.setEnabled(enabled);
}

private void setFacebookScopesEnabled(boolean enabled) {
mFacebookScopesLabel.setEnabled(enabled);
mFacebookScopeFriends.setEnabled(enabled);
mFacebookScopePhotos.setEnabled(enabled);
private void setFacebookPermissionsEnabled(boolean enabled) {
mFacebookPermissionsHeader.setEnabled(enabled);
mFacebookPermissionFriends.setEnabled(enabled);
mFacebookPermissionPhotos.setEnabled(enabled);
}

private void setGitHubPermissionsEnabled(boolean enabled) {
mGitHubPermissionsHeader.setEnabled(enabled);
mGitHubPermissionRepo.setEnabled(enabled);
mGitHubPermissionGist.setEnabled(enabled);
}

private List<String> getGoogleScopes() {
Expand All @@ -351,15 +394,26 @@ private List<String> getGoogleScopes() {

private List<String> getFacebookPermissions() {
List<String> result = new ArrayList<>();
if (mFacebookScopeFriends.isChecked()) {
if (mFacebookPermissionFriends.isChecked()) {
result.add("user_friends");
}
if (mFacebookScopePhotos.isChecked()) {
if (mFacebookPermissionPhotos.isChecked()) {
result.add("user_photos");
}
return result;
}

private List<String> getGitHubPermissions() {
List<String> result = new ArrayList<>();
if (mGitHubPermissionRepo.isChecked()) {
result.add("repo");
}
if (mGitHubPermissionGist.isChecked()) {
result.add("gist");
}
return result;
}

private void showSnackbar(@StringRes int errorMessageRes) {
Snackbar.make(mRootView, errorMessageRes, Snackbar.LENGTH_LONG).show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthProvider;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GithubAuthProvider;
import com.google.firebase.auth.GoogleAuthProvider;
import com.google.firebase.auth.PhoneAuthProvider;
import com.google.firebase.auth.TwitterAuthProvider;
Expand Down Expand Up @@ -176,6 +177,9 @@ private void populateProfile(@Nullable IdpResponse response) {
case TwitterAuthProvider.PROVIDER_ID:
providers.add(getString(R.string.providers_twitter));
break;
case GithubAuthProvider.PROVIDER_ID:
providers.add(getString(R.string.providers_github));
break;
case EmailAuthProvider.PROVIDER_ID:
providers.add(getString(R.string.providers_email));
break;
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/res/layout/auth_ui_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
android:checked="true"
android:text="@string/providers_twitter" />

<CheckBox
android:id="@+id/github_provider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/providers_github"/>

<CheckBox
android:id="@+id/email_provider"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -264,6 +271,29 @@
android:checked="false"
android:text="@string/facebook_permission_photos" />

<TextView
android:id="@+id/github_permissions_header"
style="@style/Base.TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:text="@string/github_permissions_header" />

<CheckBox
android:id="@+id/github_permission_repo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/github_permission_repo" />

<CheckBox
android:id="@+id/github_permission_gist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/github_permission_gist" />

<TextView
style="@style/Base.TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
Expand Down
25 changes: 21 additions & 4 deletions app/src/main/res/values/config.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Example: project-id.firebaseapp.com. Used for OAuth redirects -->
<string name="firebase_web_host" translatable="false">CHANGE-ME</string>

<!--
The Facebook Application ID associated with this Android application. To
use Facebook accounts with the demo application, register an application
and provide your value here.
-->
<string name="facebook_application_id" translatable="false">CHANGE-ME</string>

<!--
Facebook Application ID, prefixed by 'fb'. Enables Chrome Custom tabs.
-->
<!-- Facebook Application ID, prefixed by 'fb'. Enables Chrome Custom tabs. -->
<string name="facebook_login_protocol_scheme" translatable="false" tools:ignore="UnusedResources">fbYOUR_APP_ID</string>


Expand All @@ -19,11 +20,27 @@
<string name="twitter_consumer_key" translatable="false">CHANGE-ME</string>

<!--
Your Twitter Consumer Secret
Your Twitter Consumer Secret.

WARNING: By obtaining your Consumer Key and Consumer Secret other programs can perform API
operations as your app. Embedding the Consumer Key and Consumer Secret in your app, no matter
how obfuscated, makes it vulnerable to being stolen.
-->
<string name="twitter_consumer_secret" translatable="false">CHANGE-ME</string>


<!--
Your GitHub Client ID. To use GitHub accounts with the demo application, register an
application with GitHub and provide the following two values.
-->
<string name="github_client_id" translatable="false">CHANGE-ME</string>

<!--
Your GitHub Client Secret.

WARNING: By obtaining your Client ID and Client Secret other programs can perform API
operations as your app. Embedding the Client ID and Client Secret in your app, no matter
how obfuscated, makes it vulnerable to being stolen.
-->
<string name="github_client_secret" translatable="false">CHANGE-ME</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<string name="providers_header">Auth providers</string>
<string name="providers_google">Google</string>
<string name="providers_facebook">Facebook</string>
<string name="providers_github">GitHub</string>
<string name="providers_twitter">Twitter</string>
<string name="providers_email">Email</string>
<string name="providers_phone">Phone</string>
Expand Down Expand Up @@ -53,6 +54,10 @@
<string name="facebook_permission_friends">Friends</string>
<string name="facebook_permission_photos">Photos</string>

<string name="github_permissions_header">Example extra GitHub permissions</string>
<string name="github_permission_repo">Repo</string>
<string name="github_permission_gist">Gist</string>

<string name="options_header">Other Options</string>
<string name="options_enable_credential_selector">Enable Smart Lock\'s credential selector</string>
<string name="options_enable_hint_selector">Enable Smart Lock\'s hint selector</string>
Expand All @@ -63,6 +68,7 @@
<string name="google_label_missing_config">Google configuration missing</string>
<string name="facebook_label_missing_config">Facebook configuration missing</string>
<string name="twitter_label_missing_config">Twitter configuration missing</string>
<string name="github_label_missing_config">GitHub configuration missing</string>

<string name="sign_in_cancelled">Sign in cancelled</string>
<string name="no_internet_connection">No internet connection</string>
Expand Down
Loading