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

add configurable timeout fn param (connectionTimeoutSeconds/connectionTimeoutMillis) #701

Merged
merged 8 commits into from
Feb 2, 2022

Conversation

Jay-A-McBee
Copy link
Contributor

@Jay-A-McBee Jay-A-McBee commented Jan 21, 2022

Fixes #236 #479

Description

  • adds a connectionTimeoutSeconds fn param to prefetchConfiguration, authorize and refresh
  • adds connectionTimeoutSeconds property to AuthConfiguration type
  • adds connectionTimeoutSeconds param validation and test cases
  • converts value to milliseconds for Android platform
  • adds logic to native methods to handle new fn param
  • adds android specific test cases for time conversion (seconds -> milliseconds)

Random addition

  • adds default value for warmAndPrefetchChrome fn param (fixes 479)

Steps to verify

(not sure if this is the best way to go about it 🤷‍♂️ )

  1. Manually sync the Example/node_modules/react-native-app-auth directory with the updated ios/android dirs, react-native-app-auth.podspec and index.js files.

cp -r ios Example/node_modules/react-native-app-auth && cp -r android Example/node_modules/react-native-app-auth && cp index.js Example/node_modules/react-native-app-auth && cp react-native-app-auth.podspec Example/node_modules/react-native-app-auth

  1. change the issuer property of the identityserver config in Example/App.js to a url that will never resolve (ex. http://www.example:81.com)

  2. If the url doesn't use https protocol, add dangerouslyAllowInsecureHttpRequests: true to the argument object passed to the 'authorize' method in Example/App.js.

  3. Run the Example app and attempt to authorize through identity server. The default timeout is 60 seconds for iOS and 15 seconds for Android. It should be apparent that the configured timeout of 5 seconds is being respected.

platform === 'android' && connectionTimeout > 0
? connectionTimeout * MILLI_PER_SEC
: connectionTimeout;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course iOS uses seconds and Android milliseconds 🤦 .

@@ -78,6 +85,7 @@ export const prefetchConfiguration = async ({
serviceConfiguration,
dangerouslyAllowInsecureHttpRequests = false,
customHeaders,
connectionTimeoutSeconds = 0,
}) => {
Copy link
Contributor Author

@Jay-A-McBee Jay-A-McBee Jan 21, 2022

Choose a reason for hiding this comment

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

I wasn't able to pass a default value of null here because of the Java type. Even though Double can hold a null value, the conversion by React-Native of this arg to the Java type Double failed for null.

@@ -63,6 +63,7 @@
private final ReactApplicationContext reactContext;
private Promise promise;
private boolean dangerouslyAllowInsecureHttpRequests;
private Double connectionTimeoutMillis;
private Boolean skipCodeExchange;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used a Double instead of Integer because I saw this in the docs
Screen Shot 2022-01-20 at 7 20 03 PM

@@ -42,6 +42,7 @@ describe('AppAuth', () => {
usePKCE: true,
Copy link
Contributor Author

@Jay-A-McBee Jay-A-McBee Jan 21, 2022

Choose a reason for hiding this comment

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

Some of the test cases seem off in this file. The refresh block has some redundant authorize validation cases 🙀 - probably just a bad copy/pasta. Anyway, I'll get those shaped up.

it('throws an error when issuer is not a string and serviceConfiguration is not passed', () => {
expect(() => {
authorize({ ...config, issuer: () => ({}) });
refresh({ ...config, issuer: () => ({}) }, { refreshToken });
}).toThrow('Config error: you must provide either an issuer or a service endpoints');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Redundant authorize assertions that were mentioned.

@Jay-A-McBee Jay-A-McBee marked this pull request as ready for review February 1, 2022 20:18
README.md Outdated Show resolved Hide resolved
@Jay-A-McBee Jay-A-McBee merged commit 580372d into main Feb 2, 2022
@Jay-A-McBee Jay-A-McBee deleted the task/add_configurable_timeout branch February 2, 2022 19:42
@@ -44,12 +44,13 @@ - (dispatch_queue_t)methodQueue
subjectType: (NSString *) subjectType
tokenEndpointAuthMethod: (NSString *) tokenEndpointAuthMethod
additionalParameters: (NSDictionary *_Nullable) additionalParameters
connectionTimeoutSeconds: (double) connectionTimeoutSeconds

Choose a reason for hiding this comment

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

This line appears to have introduced a regression: #790

Proposed fix is here: #804

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to configure timeout for network request
3 participants