Credentials file#
ไฟล์ Credentials จะกำหนดวิธีการ authorize สำหรับ node ของคุณ การตั้งค่าในไฟล์นี้จะมีผลกับสิ่งที่ n8n แสดงใน Credentials modal และต้องตรงกับความต้องการ authentication ของ service ที่คุณจะเชื่อมต่อ
ในไฟล์ credentials คุณสามารถใช้ n8n UI elements ได้ทั้งหมด n8n จะเข้ารหัสข้อมูลที่ถูกเก็บไว้ใน credentials ด้วย encryption key
Structure of the credentials file#
ไฟล์ credentials จะมีโครงสร้างพื้นฐานดังนี้:
- Import statements
- สร้าง class สำหรับ credentials
- ใน class ให้กำหนด properties ที่ควบคุม authentication สำหรับ node
Outline structure#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
Parameters#
name
#
String. ชื่อภายในของ object นี้ ใช้อ้างอิงจากที่อื่นใน node
displayName
#
String. ชื่อที่ n8n ใช้แสดงใน GUI
documentationUrl
#
String. URL ไปยังเอกสาร credentials ของคุณ
properties
#
แต่ละ object จะมี:
displayName
: ชื่อที่ n8n ใช้แสดงใน GUIname
: ชื่อภายในของ object นี้ ใช้อ้างอิงจากที่อื่นใน nodetype
: ประเภทข้อมูลที่ต้องการ เช่นstring
default
: URL ที่ n8n จะใช้ทดสอบ credentials
authenticate
#
authenticate
: Object. มี object ที่บอก n8n ว่าจะ inject ข้อมูล authentication เข้าไปใน API request อย่างไร
type
#
String. ถ้าใช้ authentication แบบส่งข้อมูลใน header, body หรือ query string ให้ตั้งเป็น 'generic'
properties
#
Object. กำหนดวิธี authentication ตัวเลือกมี:
-
body
: Object. ส่งข้อมูล authentication ใน request body สามารถมี object ซ้อนกันได้1 2 3 4 5 6 7 8 9
authenticate: IAuthenticateGeneric = { type: 'generic', properties: { body: { username: '={{$credentials.username}}', password: '={{$credentials.password}}', }, }, };
-
header
: Object. ส่งข้อมูล authentication ใน request header1 2 3 4 5 6 7 8
authenticate: IAuthenticateGeneric = { type: 'generic', properties: { header: { Authorization: '=Bearer {{$credentials.authToken}}', }, }, };
-
qs
: Object. ย่อมาจาก "query string" ส่งข้อมูล authentication ใน query string ของ request1 2 3 4 5 6 7 8
authenticate: IAuthenticateGeneric = { type: 'generic', properties: { qs: { token: '={{$credentials.token}}', }, }, };
-
auth
: Object. ใช้สำหรับ Basic Auth ต้องมีusername
และpassword
เป็น key1 2 3 4 5 6 7 8 9
authenticate: IAuthenticateGeneric = { type: 'generic', properties: { auth: { username: '={{$credentials.username}}', password: '={{$credentials.password}}', }, }, };
test
#
ให้ใส่ object request
ที่มี URL และประเภท authentication ที่ n8n จะใช้ทดสอบ credential
1 2 3 4 5 6 |
|