question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expired credentials are used after re-authentication

See original GitHub issue

I have noticed this behaviour on the first request that is made after each time credentials expire.

In the code I see that there is a condition that checks if the credentials are expired. And if they are, this.authenticate() (line 128) is called before the request is made.

https://github.com/moltin/js-sdk/blob/84d891fdb8f6d3596aefaaacd88620036e3405c2/src/factories/request.js#L122-L129

But the function const req = () => {... (line 85) uses stale credentials fetched from localStorage before re-authentication.

      const credentials = JSON.parse(storage.get('moltinCredentials'))
      const req = () => {
        const headers = {
          Authorization: `Bearer: ${credentials.access_token}`,

      /* ... */

      if (
        !credentials ||
        !credentials.access_token ||
        credentials.client_id !== config.client_id ||
        Math.floor(Date.now() / 1000) >= credentials.expires
      ) {
        return this.authenticate()
          .then(req)  // <--- This uses the same credentials
          .catch(error => reject(error))

This causes the request to fail with the message

{
    "errors": [
        {
            "status": 401,
            "title": "Unable to validate access token"
        }
    ]
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
notrabcommented, Apr 26, 2018

Thanks @aravindanve I’m looking into this now and will get back to you once I confirm and patch.

1reaction
aravindanvecommented, Apr 18, 2018

I would send a PR right now, but your contribution rules look a little intimidating. 😅

I’ll try and do it later if I can take some time out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flow Connections error due to Credential Expiration
Solved: Hello All, We are having an issue with credentials expiring in Microsoft Flow Connections. The connections seem to expire every 2 weeks....
Read more >
Reset your password for expired credentials - EA Help
Your login credentials have expired, but all you need to do is reset your password. Scan the QR code or use the URL...
Read more >
CredentialExpiredException (Java Platform SE 7 )
This exception is thrown by LoginModules when they determine that a Credential has expired. For example, a LoginModule authenticating a user in its...
Read more >
I am getting an "Invalid or expired credentials" error when ...
If you receive an error message saying "Invalid or expired credentials" or "Authentication Needed" when you try to sync, you will need to...
Read more >
getting message "Authentication expired" on cisco router
If you are using local database for access, then it seems that those credentials have some how lost there privilege level or AAA...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found