Skip to content

setupAutomaticSilentRefresh() does not schedule refresh for tokens obtained from localStorage #103

Closed
@bedag-moo

Description

@bedag-moo

Reproduction

    oauth.configure({
      clientId: environment.openIdConnect.clientId,
      issuer: environment.openIdConnect.issuer,
      scope: "openid profile email",
      redirectUri: window.location.origin + "/",
      silentRefreshRedirectUri: window.location.origin + "/assets/silent-refresh.html",
      timeoutFactor: 0.002,
    });
    oauth.setStorage(localStorage);
    oauth.tokenValidationHandler = new JwksValidationHandler();
    oauth.setupAutomaticSilentRefresh();
  1. log in
  2. Press F5 to reload the app
  3. Wait a bit for the token refresh timeout (which is extra short, to simplify testing)

Expected: Token is refreshed
Actual: Token is not refreshed

Cause

setupAccessTokenTimer() is not invoked, because the service constructor calls restartRefreshTimerIfStillLoggedIn() before the storage is set, causing hasValidAccessToken() to return false.

As an aside, calcTimeout() applies the timeoutFactor relative to the current time. If an almost expired token is reloaded from local storage, the computed grace period may be too short to perform the refresh. Perhaps it would be better to use a fixed size grace period instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions