Google credential with access token or refresh token?

Hi all,

I have an app that asks users for permissions to modify their tasks. I store the refresh token on my server and would like to automate certain tasks using n8n. Currently I only see an oauth2 option in the UI, but is there a way for me to just pass an access token or a refresh token as a credential for the api so I can automate things on behalf of the user?

TLDR: The api only seems to support OAuth2 for google credentials, but I already have the oauth information stored. Is there a way for me using my stored information instead of requiring the user to login again?

Hi @Peter_Henry, I am afraid this option doesn’t exist in the UI or API yet.

However, you can import credentials via the CLI as described here: CLI commands - n8n Documentation

Example credentials I have previously exported seem to include the refresh token:

[{
    "id": 12,
    "name": "[email protected]",
    "data": {
        "clientId": "xxx",
        "clientSecret": "xxx",
        "oauthTokenData": {
            "access_token": "xxx",
            "expires_in": 3599,
            "refresh_token": "xxx",
            "scope": "https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.events",
            "token_type": "Bearer",
            "callbackQueryString": {
                "scope": "https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.events"
            }
        }
    },
    "type": "googleCalendarOAuth2Api",
    "nodesAccess": [{
        "nodeType": "n8n-nodes-base.googleCalendar",
        "date": "2022-01-16T15:53:07.680Z"
    }, {
        "nodeType": "n8n-nodes-base.googleCalendarTrigger",
        "date": "2022-01-16T15:53:07.680Z"
    }],
    "createdAt": "2022-01-16T14:52:52.382Z",
    "updatedAt": "2022-05-17T09:31:48.443Z"
}]

So I suspect you could inject a refresh token by importing a data structure like above (this example for Google Calendar) but I have not tried this before. You might want to give this a shot though.

If it doesn’t work let me know and we can still convert your question into a feature request so we can consider implementing this in a future version.