| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | import { | 
					
						
							| 
									
										
										
										
											2022-06-16 11:53:57 +02:00
										 |  |  | 	ICredentialDataDecryptedObject, | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 	ICredentialTestRequest, | 
					
						
							|  |  |  | 	ICredentialType, | 
					
						
							| 
									
										
										
										
											2022-06-16 11:53:57 +02:00
										 |  |  | 	IHttpRequestOptions, | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 	INodeProperties, | 
					
						
							| 
									
										
										
										
											2022-06-20 15:22:10 +02:00
										 |  |  | } from 'n8n-workflow'; | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export class HttpBinApi implements ICredentialType { | 
					
						
							| 
									
										
										
										
											2022-06-20 15:22:10 +02:00
										 |  |  | 	name = 'httpbinApi'; | 
					
						
							|  |  |  | 	displayName = 'HttpBin API'; | 
					
						
							|  |  |  | 	documentationUrl = 'httpbin'; | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 	properties: INodeProperties[] = [ | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-06-20 15:22:10 +02:00
										 |  |  | 			displayName: 'Token', | 
					
						
							|  |  |  | 			name: 'token', | 
					
						
							|  |  |  | 			type: 'string', | 
					
						
							|  |  |  | 			default: '', | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-06-16 11:53:57 +02:00
										 |  |  | 		// {
 | 
					
						
							|  |  |  | 		// 	displayName: "API Key",
 | 
					
						
							|  |  |  | 		// 	name: "apiKey",
 | 
					
						
							|  |  |  | 		// 	type: "string",
 | 
					
						
							|  |  |  | 		// 	default: "",
 | 
					
						
							|  |  |  | 		// },
 | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-06-20 15:22:10 +02:00
										 |  |  | 			displayName: 'Domain', | 
					
						
							|  |  |  | 			name: 'domain', | 
					
						
							|  |  |  | 			type: 'string', | 
					
						
							|  |  |  | 			default: 'https://httpbin.org', | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	]; | 
					
						
							| 
									
										
										
										
											2022-06-16 11:53:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// authenticate = {
 | 
					
						
							|  |  |  | 	// 	type: "headerAuth",
 | 
					
						
							|  |  |  | 	// 	properties: {
 | 
					
						
							|  |  |  | 	// 		name: "api-key",
 | 
					
						
							|  |  |  | 	// 		value: "={{$credentials.apiKey}}",
 | 
					
						
							|  |  |  | 	// 	},
 | 
					
						
							|  |  |  | 	// } as IAuthenticateHeaderAuth;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	authenticate = async ( | 
					
						
							|  |  |  | 		credentials: ICredentialDataDecryptedObject, | 
					
						
							| 
									
										
										
										
											2022-06-20 15:22:10 +02:00
										 |  |  | 		requestOptions: IHttpRequestOptions, | 
					
						
							| 
									
										
										
										
											2022-06-16 11:53:57 +02:00
										 |  |  | 	): Promise<IHttpRequestOptions> => { | 
					
						
							|  |  |  | 		const headers = requestOptions.headers || {}; | 
					
						
							|  |  |  | 		const authentication = { Authorization: `Bearer ${credentials.token}` }; | 
					
						
							|  |  |  | 		Object.assign(requestOptions, { | 
					
						
							|  |  |  | 			headers: { ...authentication, ...headers }, | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		return requestOptions; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 	test: ICredentialTestRequest = { | 
					
						
							|  |  |  | 		request: { | 
					
						
							| 
									
										
										
										
											2022-06-20 15:22:10 +02:00
										 |  |  | 			baseURL: '={{$credentials?.domain}}', | 
					
						
							|  |  |  | 			url: '/bearer', | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | } |