JSON Configuration
Overview
การตั้งค่านี้ใช้สำหรับควบคุมการทำงานของ ArcGIS Proxy และ ArcGIS Token Generator โดยมีเป้าหมายหลักเพื่อช่วยให้แอปพลิเคชันสามารถ:
- 🔄 ส่งคำร้องขอ (Request) ไปยัง ArcGIS REST Services โดยตรงจากเบราว์เซอร์ โดยไม่ติดปัญหา CORS
- 🔐 เข้าถึง ArcGIS Secure Services ที่ต้องมีการยืนยันตัวตน ทั้งแบบ Token-based และ OAuth2
- 🛡 จำกัดการเข้าถึง Proxy ตามค่า Referer เพื่อป้องกันการใช้งานโดยไม่ได้รับอนุญาต
การตั้งค่าแบ่งเป็น 2 ส่วนหลัก
Proxy
กำหนด Endpoint สำหรับ Proxy และ Token API รวมถึงรายชื่อ referer ที่อนุญาตให้เรียกใช้งานArcGIS
รายการ ArcGIS Services ที่ต้องการให้ Proxy ทำงานร่วมด้วย
สามารถระบุได้ทั้งแบบ Public (ไม่ต้องยืนยันตัวตน), Token-based (Username/Password), และ OAuth2 (Client ID/Secret)
{
"Proxy": {
"Path": "/arcgis-proxy",
"TokenPath": "/arcgis-token",
"AllowedReferers": [
"[REPLACE_TO_YOUR_SITE]"
]
},
"ArcGIS": [
{
"Url": "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services"
},
{
"Url": "https://enterprise.example.com/arcgis/rest/services/Admin/MapServer",
"Username": "admin",
"Password": "adminpass"
},
{
"Host": "www.arcgis.com",
"ClientId": "client-id-1",
"ClientSecret": "client-secret-1",
"OAuth2TokenEndpoint": "https://www.arcgis.com/sharing/rest/oauth2/token"
}
]
}Note
✅ การตั้งค่านี้เหมาะสำหรับทั้งสภาพแวดล้อม Development และ Production สามารถปรับขยายได้ตามความซับซ้อนของระบบที่ต้องติดต่อกับ ArcGIS หลายแหล่ง
Proxy Settings (Proxy)
| Key | คำอธิบาย |
|---|---|
Path | เส้นทาง API สำหรับใช้งาน ArcGIS Proxy (Default: /arcgis-proxy) |
TokenPath | เส้นทาง API สำหรับขอ ArcGIS Token (Default: /arcgis-token) |
AllowedReferers | รายการโดเมนที่อนุญาตให้เรียกใช้งาน Proxy – ใช้ "*" เพื่ออนุญาตทุกโดเมน (ไม่แนะนำสำหรับ Production)– ตัวอย่าง: http://localhost, https://portal-atlasx.cdg.co.th |
ArcGIS Services (ArcGIS)
ประกอบด้วยรายการของ ArcGIS Services ที่สามารถกำหนดการยืนยันตัวตนได้หลายรูปแบบ ทั้งแบบสาธารณะ, Token-based, และ OAuth2
🔓 1. Public Services (ไม่ต้องยืนยันตัวตน)
{
"Url":"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services"
}🔐 2. Token-based (ใช้กับ ArcGIS Server/Enterprise)
✅ ใช้ Username/Password ในการขอ Token
{
"Url": "https://enterprise.example.com/arcgis/rest/services/Viewer/MapServer",
"Username": "viewer",
"Password": "viewerpass"
}🔑 3. OAuth2 (ใช้กับ ArcGIS Enterprise/Online)
✅ ArcGIS Enterprise
{
"Host": "enterprise1.example.com",
"ClientId": "client-id",
"ClientSecret": "client-secret",
"OAuth2TokenEndpoint": "https://enterprise1.example.com/portal/sharing/rest/oauth2/token"
}✅ ArcGIS Online (ทั่วไป)
{
"Host": "www.arcgis.com",
"ClientId": "client-id-1",
"ClientSecret": "client-secret-1",
"OAuth2TokenEndpoint": "https://www.arcgis.com/sharing/rest/oauth2/token"
}✅ ArcGIS Online (องค์กร)
{
"Host": "yourorg.maps.arcgis.com",
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret",
"OAuth2TokenEndpoint": "https://www.arcgis.com/sharing/rest/oauth2/token"
}ตัวอย่างไฟล์ JSON
กำหนดให้โครงสร้างโปรเจคเป็นดังนี้
<project-root>/
├── Configurations/
│ └── ArcGISProxy/
│ ├── arcgis-proxy.json (Production)
│ ├── arcgis-proxy.Development.json
│ ├── arcgis-proxy.Inhouse.json
│ └── arcgis-proxy.Staging.json
├── Program.cs
├── appsettings.json
└── ...📄 arcgis-proxy.json
{
"Proxy": {
"Path": "/arcgis-proxy",
"TokenPath": "/arcgis-token",
"AllowedReferers": [
"[REPLACE_TO_YOUR_SITE]"
]
},
"ArcGIS": [
// Public services (No authentication required)
{
"Url": "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services"
},
// ArcGIS Enterprise - Token-based authentication
{
"Url": "https://enterprise.example.com/arcgis/rest/services/Admin/MapServer",
"Username": "admin",
"Password": "adminpass"
},
{
"Url": "https://enterprise.example.com/arcgis/rest/services/Viewer/MapServer",
"Username": "viewer",
"Password": "viewerpass"
},
// ArcGIS Enterprise - OAuth2
{
"Host": "enterprise1.example.com",
"ClientId": "client-id",
"ClientSecret": "client-secret",
"OAuth2TokenEndpoint": "https://enterprise1.example.com/portal/sharing/rest/oauth2/token"
},
// ArcGIS Online (www.arcgis.com) - multiple apps
{
"Host": "www.arcgis.com",
"ClientId": "client-id-1",
"ClientSecret": "client-secret-1",
"OAuth2TokenEndpoint": "https://www.arcgis.com/sharing/rest/oauth2/token"
},
{
"Host": "www.arcgis.com",
"ClientId": "client-id-2",
"ClientSecret": "client-secret-2",
"OAuth2TokenEndpoint": "https://www.arcgis.com/sharing/rest/oauth2/token"
},
// ArcGIS Online - organization-specific subdomain
{
"Host": "yourorg.maps.arcgis.com",
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret",
"OAuth2TokenEndpoint": "https://www.arcgis.com/sharing/rest/oauth2/token"
}
]
}📄 arcgis-proxy.Development.json
{
"Proxy": {
"Path": "/arcgis-proxy",
"TokenPath": "/arcgis-token",
"AllowedReferers": [
"*",
]
},
"ArcGIS": [ ... ]
}📄 arcgis-proxy.Staging.json
{
"Proxy": {
"Path": "/arcgis-proxy",
"TokenPath": "/arcgis-token",
"AllowedReferers": [
"https://portal-atlasx.cdg.co.th"
]
},
"ArcGIS": [ ... ]
}