@@ -166,8 +166,9 @@ public final class AWSMobileClient implements AWSCredentialsProvider {
166166 * Log Tag.
167167 */
168168 private static final String TAG = AWSMobileClient .class .getSimpleName ();
169- public static final String USER_AGENT = "AWSMobileClient" ;
169+ public static final String DEFAULT_USER_AGENT = "AWSMobileClient" ;
170170
171+ static final String AUTH_KEY = "Auth" ;
171172 static final String SHARED_PREFERENCES_KEY = "com.amazonaws.mobile.client" ;
172173 static final String PROVIDER_KEY = "provider" ;
173174 static final String TOKEN_KEY = "token" ;
@@ -266,6 +267,7 @@ public final class AWSMobileClient implements AWSCredentialsProvider {
266267 Auth hostedUI ;
267268 OAuth2Client mOAuth2Client ;
268269 String mUserPoolPoolId ;
270+ String userAgentOverride ;
269271
270272 enum SignInMode {
271273 SIGN_IN ("0" ),
@@ -464,10 +466,10 @@ public void run() {
464466 // Read Persistence key from the awsconfiguration.json and set the flag
465467 // appropriately.
466468 try {
467- if (awsConfiguration .optJsonObject ("Auth" ) != null &&
468- awsConfiguration .optJsonObject ("Auth" ).has ("Persistence" )) {
469+ if (awsConfiguration .optJsonObject (AUTH_KEY ) != null &&
470+ awsConfiguration .optJsonObject (AUTH_KEY ).has ("Persistence" )) {
469471 mIsPersistenceEnabled = awsConfiguration
470- .optJsonObject ("Auth" )
472+ .optJsonObject (AUTH_KEY )
471473 .getBoolean ("Persistence" );
472474 }
473475 } catch (final Exception ex ) {
@@ -476,6 +478,7 @@ public void run() {
476478 return ;
477479 }
478480
481+ userAgentOverride = awsConfiguration .getUserAgentOverride ();
479482 mContext = context .getApplicationContext ();
480483 mStore = new AWSMobileClientStore (AWSMobileClient .this );
481484
@@ -525,15 +528,21 @@ public void onUserSignedOut() {
525528 final String poolId = identityPoolJSON .getString ("PoolId" );
526529 final String regionStr = identityPoolJSON .getString ("Region" );
527530 final ClientConfiguration clientConfig = new ClientConfiguration ();
528- clientConfig .setUserAgent (USER_AGENT + " " + awsConfiguration .getUserAgent ());
531+ clientConfig .setUserAgent (DEFAULT_USER_AGENT + " " + awsConfiguration .getUserAgent ());
532+ if (userAgentOverride != null ) {
533+ clientConfig .setUserAgentOverride (userAgentOverride );
534+ }
529535 AmazonCognitoIdentityClient cibClient =
530- new AmazonCognitoIdentityClient (new AnonymousAWSCredentials ());
536+ new AmazonCognitoIdentityClient (new AnonymousAWSCredentials (), clientConfig );
531537 cibClient .setRegion (Region .getRegion (regionStr ));
532538 provider = new AWSMobileClientCognitoIdentityProvider (
533539 null , poolId , cibClient );
534540 cognitoIdentity = new CognitoCachingCredentialsProvider (
535541 mContext , provider , Regions .fromName (regionStr ));
536542 cognitoIdentity .setPersistenceEnabled (mIsPersistenceEnabled );
543+ if (userAgentOverride != null ) {
544+ cognitoIdentity .setUserAgentOverride (userAgentOverride );
545+ }
537546 } catch (Exception e ) {
538547 callback .onError (new RuntimeException ("Failed to initialize Cognito Identity; please check your awsconfiguration.json" , e ));
539548 return ;
@@ -549,7 +558,10 @@ public void onUserSignedOut() {
549558 final String pinpointEndpointId = CognitoPinpointSharedContext .getPinpointEndpoint (context , userPoolJSON .optString ("PinpointAppId" ));
550559
551560 final ClientConfiguration clientConfig = new ClientConfiguration ();
552- clientConfig .setUserAgent (USER_AGENT + " " + awsConfiguration .getUserAgent ());
561+ clientConfig .setUserAgent (DEFAULT_USER_AGENT + " " + awsConfiguration .getUserAgent ());
562+ if (userAgentOverride != null ) {
563+ clientConfig .setUserAgentOverride (userAgentOverride );
564+ }
553565 userpoolLL =
554566 new AmazonCognitoIdentityProviderClient (new AnonymousAWSCredentials (), clientConfig );
555567 userpoolLL .setRegion (com .amazonaws .regions .Region .getRegion (Regions .fromName (userPoolJSON .getString ("Region" ))));
@@ -575,6 +587,7 @@ public void onUserSignedOut() {
575587 Log .d (TAG , "initialize: OAuth2 client detected" );
576588 mOAuth2Client = new OAuth2Client (mContext , AWSMobileClient .this );
577589 mOAuth2Client .setPersistenceEnabled (mIsPersistenceEnabled );
590+ mOAuth2Client .setUserAgentOverride (userAgentOverride );
578591 } else {
579592 _initializeHostedUI (hostedUIJSON );
580593 }
@@ -638,7 +651,7 @@ JSONObject getHostedUIJSONFromJSON() {
638651 }
639652
640653 JSONObject getHostedUIJSONFromJSON (final AWSConfiguration awsConfig ) {
641- final JSONObject mobileClientJSON = awsConfig .optJsonObject ("Auth" );
654+ final JSONObject mobileClientJSON = awsConfig .optJsonObject (AUTH_KEY );
642655 if (mobileClientJSON != null && mobileClientJSON .has ("OAuth" )) {
643656 try {
644657 JSONObject hostedUIJSONFromJSON = mobileClientJSON .getJSONObject ("OAuth" );
@@ -1192,18 +1205,20 @@ public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice) {
11921205 public void getAuthenticationDetails (AuthenticationContinuation authenticationContinuation , String userId ) {
11931206 Log .d (TAG , "Sending password." );
11941207 try {
1195- if (awsConfiguration .optJsonObject ("Auth" ) != null &&
1196- awsConfiguration .optJsonObject ("Auth" ).has ("authenticationFlowType" ) &&
1197- awsConfiguration .optJsonObject ("Auth" ).getString ("authenticationFlowType" ).equals ("CUSTOM_AUTH" )
1208+ if (
1209+ awsConfiguration .optJsonObject (AUTH_KEY ) != null &&
1210+ awsConfiguration .optJsonObject (AUTH_KEY ).has ("authenticationFlowType" ) &&
1211+ awsConfiguration .optJsonObject (AUTH_KEY ).getString ("authenticationFlowType" ).equals ("CUSTOM_AUTH" )
11981212 ) {
1199- final HashMap <String , String > authParameters = new HashMap <String ,String >();
1213+ final HashMap <String , String > authParameters = new HashMap <String , String >();
12001214 authenticationContinuation .setAuthenticationDetails (new AuthenticationDetails (username , password , authParameters , validationData ));
12011215 } else {
12021216 authenticationContinuation .setAuthenticationDetails (new AuthenticationDetails (username , password , validationData ));
12031217 }
12041218 } catch (JSONException e ) {
12051219 e .printStackTrace ();
12061220 }
1221+
12071222 authenticationContinuation .continueTask ();
12081223 }
12091224
@@ -1451,9 +1466,9 @@ public void signOut() {
14511466 mFederatedLoginsMap .clear ();
14521467 mStore .clear ();
14531468 String hostedUIJSON = null ;
1454- if (awsConfiguration .optJsonObject ("Auth" ) != null && awsConfiguration .optJsonObject ("Auth" ).has ("OAuth" )) {
1469+ if (awsConfiguration .optJsonObject (AUTH_KEY ) != null && awsConfiguration .optJsonObject (AUTH_KEY ).has ("OAuth" )) {
14551470 try {
1456- hostedUIJSON = awsConfiguration .optJsonObject ("Auth" ).getJSONObject ("OAuth" ).toString ();
1471+ hostedUIJSON = awsConfiguration .optJsonObject (AUTH_KEY ).getJSONObject ("OAuth" ).toString ();
14571472 } catch (JSONException e ) {
14581473 e .printStackTrace ();
14591474 }
@@ -3815,32 +3830,6 @@ class AWSMobileClientCognitoIdentityProvider extends AWSAbstractCognitoIdentityP
38153830
38163831 boolean isDeveloperAuthenticated ;
38173832
3818- /**
3819- * An extension of the AbstractCognitoProvider that is used to communicate
3820- * with Cognito.
3821- *
3822- * @param accountId the account id of the developer
3823- * @param identityPoolId the identity pool id of the app/user in question
3824- */
3825- public AWSMobileClientCognitoIdentityProvider (String accountId , String identityPoolId ) {
3826- this (accountId , identityPoolId , new ClientConfiguration ());
3827- }
3828-
3829- /**
3830- * An extension of the AbstractCognitoProvider that is used to communicate
3831- * with Cognito.
3832- *
3833- * @param accountId the account id of the developer
3834- * @param identityPoolId the identity pool id of the app/user in question
3835- * @param clientConfiguration the configuration to apply to service clients
3836- * created
3837- */
3838- public AWSMobileClientCognitoIdentityProvider (String accountId , String identityPoolId ,
3839- ClientConfiguration clientConfiguration ) {
3840- this (accountId , identityPoolId , new AmazonCognitoIdentityClient
3841- (new AnonymousAWSCredentials (), clientConfiguration ));
3842- }
3843-
38443833 /**
38453834 * An extension of the AbstractCognitoProvider that is used to communicate
38463835 * with Cognito.
@@ -3857,7 +3846,7 @@ public AWSMobileClientCognitoIdentityProvider(String accountId, String identityP
38573846
38583847 @ Override
38593848 protected String getUserAgent () {
3860- return " AWSMobileClient" ;
3849+ return AWSMobileClient . DEFAULT_USER_AGENT ;
38613850 }
38623851
38633852 /**
0 commit comments