| 
									
										
										
										
											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, | 
					
						
							|  |  |  | } from "n8n-workflow"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class HttpBinApi implements ICredentialType { | 
					
						
							| 
									
										
										
										
											2022-06-14 17:01:15 +02:00
										 |  |  | 	name = "httpbinApi"; | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 	displayName = "HttpBin API"; | 
					
						
							|  |  |  | 	documentationUrl = "httpbin"; | 
					
						
							|  |  |  | 	properties: INodeProperties[] = [ | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-06-16 11:53:57 +02:00
										 |  |  | 			displayName: "Token", | 
					
						
							|  |  |  | 			name: "token", | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 			type: "string", | 
					
						
							|  |  |  | 			default: "", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-06-16 11:53:57 +02:00
										 |  |  | 		// {
 | 
					
						
							|  |  |  | 		// 	displayName: "API Key",
 | 
					
						
							|  |  |  | 		// 	name: "apiKey",
 | 
					
						
							|  |  |  | 		// 	type: "string",
 | 
					
						
							|  |  |  | 		// 	default: "",
 | 
					
						
							|  |  |  | 		// },
 | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			displayName: "Domain", | 
					
						
							|  |  |  | 			name: "domain", | 
					
						
							|  |  |  | 			type: "string", | 
					
						
							|  |  |  | 			default: "https://httpbin.org", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	]; | 
					
						
							| 
									
										
										
										
											2022-06-16 11:53:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// 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; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 	test: ICredentialTestRequest = { | 
					
						
							|  |  |  | 		request: { | 
					
						
							| 
									
										
										
										
											2022-06-16 11:53:57 +02:00
										 |  |  | 			baseURL: "={{$credentials?.domain}}", | 
					
						
							|  |  |  | 			url: "/bearer", | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | } |