Skip to content
This repository was archived by the owner on Jan 26, 2025. It is now read-only.
This repository was archived by the owner on Jan 26, 2025. It is now read-only.

Security Component Bug #921

Description

@abodnar63

I'm submitting this issue for the package(s):

  • jwt-verifier
  • okta-angular
  • oidc-middleware
  • okta-react
  • okta-react-native

I'm submitting a:

  • Bug report
  • Feature request
  • Other (Describe below)

Current behavior

I've noticed that the Security component creates a new instance of AuthService after every rendering. Potentially it could cause a lot of different concurrency issues but right now I found issue in token renew functionality. If the application renders multiple times the Security component than during token renew it will send multiple requests to the token endpoint:
Screenshot 2020-09-27 at 20 27 34
Screenshot 2020-09-27 at 20 33 13

I see that you tried to prevent such behaviour with useMemo but the problem is that useMemo compares dependencies by referential equality. When application renders the component it gets a new object of the properties. Props could have the same attributes but for every render, it is a new Object. Like {} === {} returns false.

Expected behavior

I would expect to have one instance of AuthService to prevent multiple calls to API. I think there a few ways to fix it. One of them is to use a Singletone pattern for service creation and do a deep check of props before creating the new instance.

Minimal reproduction of the problem with instructions

To reproduce the issue with token auto-renew you can just get this sample https://github.com/okta/samples-js-react/tree/master/okta-hosted-login. You need to render https://github.com/okta/samples-js-react/blob/master/okta-hosted-login/src/App.jsx for multiple times so you can use a timer or add a button which will change the state of the component after every click
Screenshot 2020-09-27 at 21 16 30
In config enable autoRenew:

tokenManager: {
      storage: 'sessionStorage',
      autoRenew: true
 }

If you don't want to wait one hour for session expiration you can change manually value of expiresAt for idToken and accessToken in session storage okta-token-storage and refresh the page to read new values by application. For calculating expiresAt you can use this code: Math.round((new Date().getTime() + 1000 * 60 * 2 )/ 1000) It returns expiresAt value for 2 minutes later.
Render the component multiple times after refreshing by clicking the button and you will see multiple requests for token renew after one minute and a half.

Extra information about the use case/user story you are trying to implement

Temporary workaround for dealing with this issue is to prevent multiple rendering of Security component.

Environment

  • Package Version: "@okta/okta-react": "3.0.7",
  • Browser: Chrome
  • OS: macOS Catalina
  • Node version (node -v): v12.18.3
  • Other:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions