Remove unused fields When extends OAuth2Api

Question

I’m developing a credentials class and I extend from OAuth2Api. How can I remove the Client ID and Client Secret fields in OAuth2Api?

Code

/* eslint-disable n8n-nodes-base/cred-filename-against-convention */
import { ICredentialType, INodeProperties } from 'n8n-workflow';

export class NhanhvnOAuth2Api implements ICredentialType {
	name = 'nhanhvnOAuth2Api';
	extends = ['oAuth2Api'];
	displayName = 'Nhanhvn OAuth2 API';
	documentationUrl =
		'https://www.notion.so/Qonto-Sandbox-Useful-Information-3f1e39b04dbc4ea380bdd46500f9762f';
	properties: INodeProperties[] = [
		{
			displayName: 'API version',
			name: 'apiVersion',
			type: 'number',
			default: 2.0,
			required: true,
		},
		{
			displayName: 'APP ID',
			name: 'appId',
			type: 'number',
			default: '',
			required: true,
		},
		{
			displayName: 'Return Link',
			name: 'returnLink',
			type: 'string',
			default: '',
			required: true,
		},
		{
			displayName: 'Authorization URL',
			name: 'authUrl',
			type: 'hidden',
			required: true,
			default: `={{ $self["environment"] === "sandbox" ? "myLink" : "myLink" }}`,
		},
		{
			displayName: 'Access Token URL',
			name: 'accessTokenUrl',
			type: 'hidden',
			required: true,
			default:
				'={{ $self["environment"] === "sandbox" ? "myLink" : "myLink" }}',
		},
		{
			displayName: 'Grant Type',
			name: 'grantType',
			type: 'hidden',
			default: 'authorizationCode',
		},
		{
			displayName: 'Authentication',
			name: 'authentication',
			type: 'hidden',
			default: 'body',
		},
		{
			displayName: 'Auth URI Query Parameters',
			name: 'authQueryParameters',
			type: 'hidden',
			required: false,
			default: '',
			description: '',
		},
	];
}

Hi @Hungnpv,
you can’t remove the Client ID and Client Secrets, but you could hide them and assign default values by redeclaring the properties in your NhanhvnOAuth2Api credential.

{
	displayName: 'Client ID',
	name: 'clientId',
	type: 'hidden',
	default: 'XXX'
},

But since you are developing an OAuth2 credential the client id and secret are required to authenticate against an OAuth service. Why are you trying to remove them?

2 Likes

Thank you for your answer. In my case, instead of using Client ID and Client Secrets, I use appId and returnUrl. Is there any way to change Client ID = appId and Client Secrets = returnUrl?

I suppose not with oAuth, as it requires such fields:

Hey @Hungnpv,
as @barn4k already mentioned this wouldn’t work. You can’t just remap Client Secrets to returnUrl and expect it to work. Under the hood n8n follows the OAuth2 strategy and will automatically send the redirect url according to you instance url/domain.

1 Like