Access saved credentials from "expressions"

Is there a way to access a saved API key and token via expressions, in the same way that we can access values from other nodes with $node()?

Use case: I want to send a POST to a Trello API that would add an attachment to a card. It uses query params for key and token, which are already saved in the Trello API credentials I have set up. Is there a simple way to access those for situations like this? There are so many endpoints in APIs that it would be unrealistic to have them all within n8n, so this is a workaround idea I’m playing with.

1 Like

@wilsongoode as far as I know this is yet not possible. I see how that can be handy for some use cases.

Is there a workaround for this? I want to use postgres credentials in a function node. Trying to avoid creating my own node for now.

No there is sadly no good workaround. The only thing you can do is to store the credentials in the workflow or reference them from somewhere else for example an environment variable. But no matter what the credentials would then either be saved clear text in the workflow or in the past-executions (at least if you save them).

1 Like

Oh okay, thanks for the quick reply. I guess creating my own node would be the solution then!

Adding my use-case here. Want to fetch some personal financial data (investments, utility bills, credit card bills, etc) and notify myself. Since the passwords are very sensitive in the HTTP requests I’m making, I can’t in good conscience hard-code them as plain-text…

What would really help me is

  • Allow accessing credentials from an expression
  • Add arbitrary credentials to HTTP request node (maybe just a JSON object to story arbitrary data)
  • Add option to HTTP request node to never save request history
4 Likes

Thanks a lot for adding your use-case @patrickjm!

I just changed the topic to “Feature Request” so that everybody that is interested in it can up-vote it.

2 Likes

Hello, any news on this feature? I’m testing out n8n and I love it, but sometimes I need to use code in between nodes which also make use of access tokens / oauth2 to validate the api calls.

1 Like

I agree that the ability to input and save credentials (perhaps to local browser storage) would be very helpful. Consider the use case where an HTTP request requires an Oath2 Resource Owner Password Credentials Grant Type. This is not currently supported with normal Oath2 credentials, so I have to authenticate with a regular HTTP request. If I export the workflow JSON, the unencrypted credentials are visible.

The only way I can think of to make this work currently is to use something like Bubble to gather the credentials and pass those over a webhook to start the n8n workflow. I’m not sure I want to go there.

Here’s an example of code from Postman:

curl -X POST
https://<yoursubdomain.xyz.com>/oauth2/token
-F client_id=<your_client_id>
-F client_secret=<your_client_secret>
-F grant_type=password
-F scope=api
-F username=<your_username>
-F password=<your_password>

Response:

{
“access_token”: “ghi567faxxxxxxfb3adef9492def4bb83f8cd266”,
“expires_in”: 3600,
“token_type”: “Bearer”,
“scope”: “api”,
“refresh_token”:“7dbabca33def3fa0473cxxxxxxeb8feghi407a5b”
}

I think this would add superpowers to n8n. First, you get from the ability to make any arbitrary API calls to any authenticated service - if you need anything beyond what the default “module” provides.

But beyond that, consider - for instance - this use case: using a saved Google Drive OAuth credential to create an arbitrary authenticated API call to the Drive API which - for whatever reason - is currently not part the default module.

Now, because I need this API as part of the flow I can’t use n8n at all for my workflow since that would fragment my setup so I need to basically develop the entire flow from scratch. Even the parts that do have a dedicated module.

Welcome to the community @roses ! Thanks a lot for your input!

We are currently working on something that will allow users to use existing node credentials (like Google Drive OAuth2) and make custom requests.

6 Likes

Is there a PR/branch for this?

No, not yet. The most backend code is already in n8n, what is still missing is the frontend part. Is however already designed and we will start with implementing it soon.

2 Likes

Hello just adding another use case for this which is calling the n8n rest api (with user management enabled). Current workarounds for this all have the password saved in clear text e.g. How to authenticate for REST API with Users management activated?

This is def needed to eliminate clear text in many use cases the default credentials are not flexible enough for many REST APIs that need to have creds sent in the body

Hi @joeldeteves, have you checked out some of the latest releases? @RicardoE105 added that to the 0.199.0 release, there is now a toggle between sending credentials in the header or body for Oauth2.
I don’t know if that fix/update is affecting other default nodes with credentials in general but it certainly worked well for my own workflows using the generic Oauth2 credentials.

Cheers and thanks Ricardo!

2 Likes

Awesome! This is exactly what I was looking for. I didn’t see it because I was using the Microsoft Ouath2 API - wonder if this will get added to the other Oauth2 creds eventually because it would be useful to have it there. cc @RicardoE105 for visibility

PS - I can use this with Microsoft as well so that makes it a little redundant for my use case :slight_smile:

But if “Microsoft Oauth2” is just a generic one labelled “Microsoft” for organizational purposes, it makes sense to add this as an option there.

Adding to this @RicardoE105 not only would accessing saved credentials be useful for adding via an expression to any field (something that comes up frequently when dealing with tokens) but it would be nice to have a Generic Credential type that lets you add as many encrypted fields as you want, with or withour usernames - you would then be able to call those using an expression in the node

IMHO that would offer a lot of flexibility and solve a big problem, not sure how feasible this is

2 Likes

What do you mean with add it to other OAuth2 creds? All OAuth2 credentials should have this.

In the Microsoft Oauth2 credential there is no option to send in the body.

However that is okay because we can use a generic Oauth2 node instead.