alexziskind1 / nativescript-oauth2

Other
85 stars 93 forks source link

method refreshTokenWithCompletion does not complete the promise if the variables this.provider.tokenEndpoint or this.tokenResult do not exist #191

Closed erodriguezh closed 2 years ago

erodriguezh commented 2 years ago

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

Calling the method refreshTokenWithCompletion does not complete the promise if the variables this.provider.tokenEndpoint or this.tokenResult do not exist. This leaves the promise in limbo forever and leaving the user without feedback.

To reproduce it call refreshTokenWithCompletion without logging in.

Expected result -> I get an error that completes the Promise saying that either this.provider.tokenEndpoint or this.tokenResult do not exist.

Actual result -> The promise never completes

Is there any code involved?

Call from demo code

      this.getClient().refreshTokenWithCompletion((tokenData: ITnsOAuthTokenResult, error) => {
        if (error) {
          console.error('back to main page with error: ');
          console.error(error);
        } else {
          console.log('back to main page with access token: ');
        }
      });

Call within the plugin in file oauth.ts

// refreshTokenWithCompletion calls an internal function callRefreshEndpointWithCompletion
public refreshTokenWithCompletion(completion?: TnsOAuthClientLoginBlock) {
    if (this.provider) {
      this.callRefreshEndpointWithCompletion(completion);
    } else {
      completion(null, "Provider is not configured");
    }
  }

private callRefreshEndpointWithCompletion(
    completion?: TnsOAuthClientLoginBlock
) {
    if (!this.provider.tokenEndpoint) {
      return; // Instead return an error using completion(null, error) to complete the Promise;
    }
    if (!this.tokenResult) {
      return; // Instead return an error using completion(null, error) to complete the Promise;
    }

    ...function continues
    );

    connection.startTokenRefresh();
  }