Multiple Credentials of Same Type Not Using Unique JWTs

I’ve build (and gotten confirmed) a custom node 1Shot API. It creates its own credential type but it just extends the “oAuth2Api” credential with an added field. In our instance, we have defined 2 credentials, using different API keys, with different permissions. In our node, there’s some drop downs powered by our API, which should return different results based on the credential you have selected.

This isn’t happening.

When I switch from Credential A to B, no new token is being requested, and the token for credential A is presented to the system for the dropdown. This results in us returning a 403 forbidden response, which is correct. We have the node configured to return refresh the token when it gets a 401 response, and this works. But relying on that mechanism for managing multiple credentials just doesn’t make sense to me. I would wager that if I switched the credential, got a 401 response instead of 403, that it would refresh the token using Credential B. Problem is, we have multiple workflows with different permissions and need tokens for A and B, having to fail a call first to trigger a switch is not going to work, besides the fact that I’d have to change the error codes in our whole product since I can only specify a single refresh the token error.

I’m hoping I’m missing something here. I’ve been looking in the n8n source code but I’m not seeing it. AI hallucinated a “uniqueIdentifier” requirement, but that should just be the internal CredentialId. How can I make n8n track a unique token for multiple instances of credential types?

1 Like

I asked around in Telegram a bit and got some advice. We tried using a generic HTTP Request node with our credentials, and it works. But it also makes our node work! It didn’t before, but after the HTTP Request node test, our node is working properly. I interpret this to mean that the tokens are being generated and cached independently, but somehow, our node is not triggering or using the proper token by itself.

I looked at our code, and we’ve added a custom Business Id field to our credential. At the start of our execute function, we often need to grab the Business Id from the selected credential, which I do like this:

const credentials = await context.getCredentials(‘oneShotOAuth2Api’);
const businessId = credentials.businessId as string;

I did notice in the typing, that getCredentials() accepts a second parameter for the index, which makes me think that it’s returning the first credential instead of the selected credential. However, I can’t find in the n8n github any other node that supplies this index, so this bug would not be unique to me.

For reference, this is my node: GitHub - UXlySoftware/n8n-nodes-1shot: 1Shot API n8n Node

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