mirror of
				https://github.com/n8n-io/n8n-nodes-starter.git
				synced 2025-11-03 15:42:26 -06:00 
			
		
		
		
	
		
			
				
	
	
		
			60 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import {
 | 
						|
	ICredentialDataDecryptedObject,
 | 
						|
	ICredentialTestRequest,
 | 
						|
	ICredentialType,
 | 
						|
	IHttpRequestOptions,
 | 
						|
	INodeProperties,
 | 
						|
} from 'n8n-workflow';
 | 
						|
 | 
						|
export class HttpBinApi implements ICredentialType {
 | 
						|
	name = 'httpbinApi';
 | 
						|
	displayName = 'HttpBin API';
 | 
						|
	documentationUrl = 'httpbin';
 | 
						|
	properties: INodeProperties[] = [
 | 
						|
		{
 | 
						|
			displayName: 'Token',
 | 
						|
			name: 'token',
 | 
						|
			type: 'string',
 | 
						|
			default: '',
 | 
						|
		},
 | 
						|
		// {
 | 
						|
		// 	displayName: "API Key",
 | 
						|
		// 	name: "apiKey",
 | 
						|
		// 	type: "string",
 | 
						|
		// 	default: "",
 | 
						|
		// },
 | 
						|
		{
 | 
						|
			displayName: 'Domain',
 | 
						|
			name: 'domain',
 | 
						|
			type: 'string',
 | 
						|
			default: 'https://httpbin.org',
 | 
						|
		},
 | 
						|
	];
 | 
						|
 | 
						|
	// authenticate = {
 | 
						|
	// 	type: "headerAuth",
 | 
						|
	// 	properties: {
 | 
						|
	// 		name: "api-key",
 | 
						|
	// 		value: "={{$credentials.apiKey}}",
 | 
						|
	// 	},
 | 
						|
	// } as IAuthenticateHeaderAuth;
 | 
						|
 | 
						|
	authenticate = async (
 | 
						|
		credentials: ICredentialDataDecryptedObject,
 | 
						|
		requestOptions: IHttpRequestOptions,
 | 
						|
	): Promise<IHttpRequestOptions> => {
 | 
						|
		const headers = requestOptions.headers || {};
 | 
						|
		const authentication = { Authorization: `Bearer ${credentials.token}` };
 | 
						|
		Object.assign(requestOptions, {
 | 
						|
			headers: { ...authentication, ...headers },
 | 
						|
		});
 | 
						|
		return requestOptions;
 | 
						|
	};
 | 
						|
 | 
						|
	test: ICredentialTestRequest = {
 | 
						|
		request: {
 | 
						|
			baseURL: '={{$credentials?.domain}}',
 | 
						|
			url: '/bearer',
 | 
						|
		},
 | 
						|
	};
 | 
						|
}
 |