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

forceRefreshSession prematurely completes its observable #767

Closed
1619digital opened this issue Jun 1, 2020 · 3 comments
Closed

forceRefreshSession prematurely completes its observable #767

1619digital opened this issue Jun 1, 2020 · 3 comments
Labels

Comments

@1619digital
Copy link

I'm having difficultly subscribing to forceRefreshSession with consistent results - here's what I think is happening -

  1. forceRefreshSession observes refreshSessionWithIFrameCompleted$
  2. refreshSessionWithIFrameCompleted$ is internally the Subject for silentRenewEventHandler
  3. The Iframe does it's thing, and silentRenewEventHandler is triggered - it fires a status back to refreshSessionWithIFrameCompleted$ via fireRefreshWithIframeCompleted (all this works as expected)
  4. This is where I think the problem is - although fireRefreshWithIframeCompleted correctly updates the internal refreshSessionWithIFrameCompleted$ Subject, it then sets the Subject to complete
  5. So, every subsequent time you do forceRefreshSession, even though it works (ie refreshes the session), you don't get anything back to observe, because, even though fireRefreshWithIframeCompleted tries to set the Subject value, it's already complete and so doesn't do anything.

It's a bit obscure - I picked it up because I'm doing a session refresh immediately when a browser tab comes back into focus. Thanks.

@damienbod damienbod added the bug label Jun 1, 2020
@damienbod
Copy link
Owner

@PartyArk We have a bug here, which we fix now for the next version. Thanks for reporting

Greetings Damien

@1619digital
Copy link
Author

Hi thanks for taking a look at this; I jumped the gun a bit earlier, but now have had a look at your fix.

I tried it out but there are a couple of issues I found

  1. If silent renew returns an error, the callbackContext can return a result before the startRefreshSession is completed. So you can't wait for the first to complete. If you do that, you can have a scenario where you'll never get a result.

  2. Because there is a BehaviorSubject, you can get back null when you first subscribe (e.g. load a new tab), which is an error - not sure what the thinking behind changing it is.

Here's what I did -

  1. set the refreshSessionWithIFrameCompletedInternal$ back to a Subject (not BehaviorSubject)

  2. the key routine in forceRefreshSession looks like this -


      // get the first results from these two
      const refreshSession$ = this.startRefreshSession().pipe(first());
      const callBackContext$ = this.silentRenewService.refreshSessionWithIFrameCompleted$.pipe(first());

      return forkJoin(refreshSession$, callBackContext$).pipe(
        map(([sessionResult, callbackContext]) => {

          // ensure session setup
          if (sessionResult !== true) { return null; }

          // indicates an error in the callback
          if (callbackContext === null) { return null; }

          const isAuthenticated = callbackService.authStateService.areAuthStorageTokensValid();
          if (isAuthenticated) {
            return {
              idToken: callbackContext?.authResult?.id_token as string,
              accessToken: callbackContext?.authResult?.access_token as string,
            };
          }
          return null; // did not receive valid tokens
        })
      );

Hope that helps, I'd do a pull but can't from here.

@damienbod
Copy link
Owner

fixed in version 11.1.3, thanks for reporting

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

No branches or pull requests

2 participants