| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | import { | 
					
						
							| 
									
										
										
										
											2022-06-29 14:12:28 +02:00
										 |  |  | 	IAuthenticateGeneric, | 
					
						
							| 
									
										
										
										
											2022-06-14 16:31:05 +02:00
										 |  |  | 	ICredentialTestRequest, | 
					
						
							|  |  |  | 	ICredentialType, | 
					
						
							|  |  |  | 	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'; | 
					
						
							| 
									
										
										
										
											2022-07-05 14:37:49 +02:00
										 |  |  | 	documentationUrl = 'http://httpbin.org/#/Auth/get_bearer'; | 
					
						
							| 
									
										
										
										
											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-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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-29 14:12:28 +02:00
										 |  |  | 	// This allows the credential to be used by other parts of n8n
 | 
					
						
							|  |  |  | 	// stating how this credential is injected as part of the request
 | 
					
						
							|  |  |  | 	// An example is the Http Request node that can make generic calls
 | 
					
						
							|  |  |  | 	// reusing this credential
 | 
					
						
							|  |  |  | 	authenticate = { | 
					
						
							|  |  |  | 		type: 'generic', | 
					
						
							|  |  |  | 		properties: { | 
					
						
							| 
									
										
										
										
											2022-06-29 16:27:55 +02:00
										 |  |  | 			headers: { | 
					
						
							|  |  |  | 				Authorization: '={{"Bearer " + $credentials.token}}', | 
					
						
							| 
									
										
										
										
											2022-06-29 14:12:28 +02:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} as IAuthenticateGeneric; | 
					
						
							| 
									
										
										
										
											2022-06-16 11:53:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-29 14:12:28 +02:00
										 |  |  | 	// The block below tells how this credential can be tested
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | } |