adminAuth.tokens() getting called multiple times on client load

Hi,

I have implemented authorization flow using adminAuth.tokens().

I have noticed a strange behavior where the callback will trigger 16 times when the application loads.

See following code snippet:

...
let tokenHits = 0;

...

            adminAuth: {
                tokens: async function(token) {
                    tokenHits++;
                    console.log(`token: ${token} | times: ${tokenHits}`)
                    return { username: 'admin', permissions: '*' };
                }
            },

Request url (In browser):
http://localhost:1880?access_token=TOKEN

Output:

token: TOKEN | times: 1
token: TOKEN | times: 2
token: TOKEN | times: 3
token: TOKEN | times: 4
token: TOKEN | times: 5
token: TOKEN | times: 6
token: TOKEN | times: 7
token: TOKEN | times: 8
token: TOKEN | times: 9
token: TOKEN | times: 10
token: TOKEN | times: 11
token: TOKEN | times: 12
token: TOKEN | times: 13
token: TOKEN | times: 14
token: TOKEN | times: 15
token: TOKEN | times: 16

In my real code I send an http request to resolve the user permissions and subsequently sending 16 identical http requests.

Not sure if this is working as intended and I missed something or a bug.

Versions:

  • node: v12.16.1
  • node-red:2.2.2

Thanks

Hi,

The tokens function is called for each request that includes a token so that it can be validated and mapped to a user.

When loading the editor it makes multiple calls to the admin api to load the various pieces needed.

It is up to your code to do whatever internal caching of token validation you decide is appropriate.

Hi knolleary,
Thank you for clearing it out.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.