Skip to content

Commit cda489b

Browse files
rlatapy-lunaminbi
authored andcommitted
Use intent to pass custom flags for CognitoAuth client (#608)
1 parent 3d18823 commit cda489b

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

aws-android-sdk-cognitoauth/src/main/java/com/amazonaws/mobileconnectors/cognitoauth/Auth.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import android.content.Context;
2121
import android.net.Uri;
22+
import android.os.Bundle;
2223
import android.util.Patterns;
2324

2425
import com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthInvalidParameterException;
@@ -59,6 +60,11 @@ public final class Auth {
5960
*/
6061
private final String idpIdentifier;
6162

63+
/**
64+
* Bundle containing customization flags for chrome custom tab
65+
*/
66+
private final Bundle customTabExtras;
67+
6268
/**
6369
* This identifies the settings for additional userPool features.
6470
*/
@@ -143,7 +149,8 @@ private Auth(final Context context,
143149
final AuthHandler userHandler,
144150
final boolean advancedSecurityDataCollectionFlag,
145151
final String identityProvider,
146-
final String idpIdentifier) {
152+
final String idpIdentifier,
153+
final Bundle customTabExtras) {
147154
this.context = context;
148155
this.appWebDomain = appWebDomain;
149156
this.appId = appId;
@@ -158,6 +165,7 @@ private Auth(final Context context,
158165
this.advancedSecurityDataCollectionFlag = advancedSecurityDataCollectionFlag;
159166
this.identityProvider = identityProvider;
160167
this.idpIdentifier = idpIdentifier;
168+
this.customTabExtras = customTabExtras;
161169
getCurrentUser();
162170
}
163171

@@ -222,6 +230,11 @@ public static final class Builder {
222230
*/
223231
private String mIdpIdentifier;
224232

233+
/**
234+
* Bundle of flags to customize chrome custom tab UI
235+
*/
236+
private Bundle mCustomTabsExtras;
237+
225238
/**
226239
* Flag indicating if data collection for advanced security mode is enabled.
227240
* By default this is enabled.
@@ -400,6 +413,20 @@ public Builder setIdpIdentifier(final String mIdpIdentifier) {
400413
return this;
401414
}
402415

416+
/**
417+
* Sets customization bundle. This allow to customize chrome custom tab.
418+
* <p>
419+
* Optional. Set a bundle to customize UI
420+
* </p>
421+
* @param mCustomTabsExtras Optional: Pass to chrome custom tab a bundle of customization flags
422+
* @return A reference to this builder.
423+
*/
424+
@SuppressWarnings("checkstyle:hiddenfield")
425+
public Builder setCustomTabsExtras(final Bundle mCustomTabsExtras) {
426+
this.mCustomTabsExtras = mCustomTabsExtras;
427+
return this;
428+
}
429+
403430
/**
404431
* Instantiates {@link Auth} with the set options.
405432
* @return {@link Auth}.
@@ -417,7 +444,8 @@ public Auth build() {
417444
this.mUserHandler,
418445
this.mAdvancedSecurityDataCollectionFlag,
419446
this.mIdentityProvider,
420-
this.mIdpIdentifier);
447+
this.mIdpIdentifier,
448+
this.mCustomTabsExtras);
421449
}
422450

423451

@@ -559,6 +587,13 @@ public String getIdpIdentifier() {
559587
return idpIdentifier;
560588
}
561589

590+
/**
591+
* @return Extra customization bundle for this {@link Auth} instance.
592+
*/
593+
public Bundle getCustomTabExtras() {
594+
return customTabExtras;
595+
}
596+
562597
/**
563598
* Use this method to get tokens for a user, the tokens are returned though the callback.
564599
* {@link AuthHandler#onSuccess(AuthUserSession)}.

aws-android-sdk-cognitoauth/src/main/java/com/amazonaws/mobileconnectors/cognitoauth/AuthClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ private void launchCustomTabs(final Uri uri) {
531531
try {
532532
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(mCustomTabsSession);
533533
mCustomTabsIntent = builder.build();
534+
if(pool.getCustomTabExtras() != null)
535+
mCustomTabsIntent.intent.putExtras(pool.getCustomTabExtras());
534536
mCustomTabsIntent.intent.setPackage(ClientConstants.CHROME_PACKAGE);
535537
mCustomTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
536538
mCustomTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

0 commit comments

Comments
 (0)