Build secure web forms with LINE authentication for n8n workflows
สร้างฟอร์มเว็บที่ปลอดภัยด้วยการยืนยันตัวตน LINE สำหรับเวิร์กโฟลว์ n8n
Basic HTML template:
แม่แบบ HTML พื้นฐาน:
<!DOCTYPE html> <html> <head> <title>My LIFF App</title> </head> <body> <div id="loading">Loading...</div> <div id="profile" style="display:none"> <h2>Welcome!</h2> <img id="userPhoto" width="100"> <p>Name: <span id="userName"></span></p> <button onclick="sendToN8N()">Send to n8n</button> </div> <script src="https://static.line-scdn.net/liff/edge/2/sdk.js"></script> <script> const LIFF_ID = "YOUR_LIFF_ID_HERE"; const WEBHOOK = "YOUR_N8N_WEBHOOK_URL"; window.onload = async () => { try { await liff.init({ liffId: LIFF_ID }); if (!liff.isLoggedIn()) { liff.login(); return; } const profile = await liff.getProfile(); document.getElementById('loading').style.display = 'none'; document.getElementById('profile').style.display = 'block'; document.getElementById('userPhoto').src = profile.pictureUrl; document.getElementById('userName').textContent = profile.displayName; } catch (error) { alert('LIFF init failed: ' + error.message); } }; async function sendToN8N() { const profile = await liff.getProfile(); const data = { user: { name: profile.displayName, id: profile.userId }, token: liff.getIDToken() }; fetch(WEBHOOK, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }).then(() => alert('Sent to n8n!')); } </script> </body> </html>
https://liff.line.me/YOUR_LIFF_ID
https://liff.line.me/YOUR_LIFF_ID
n8n Function node code for token verification:
โค้ด n8n Function node สำหรับยืนยัน token:
const idToken = $json.token; if (idToken) { const [header, payload, signature] = idToken.split('.'); const userData = JSON.parse(Buffer.from(payload, 'base64').toString()); // Check expiration if (userData.exp * 1000 < Date.now()) { throw new Error('Token expired'); } // Verify channel ID if (userData.aud !== 'YOUR_CHANNEL_ID') { throw new Error('Invalid channel'); } return { lineUserId: userData.sub, displayName: $json.user.name, verified: true }; }
Your LINE LIFF web app is set up and ready to collect authenticated user data for your n8n workflows.
แอป LINE LIFF ของคุณพร้อมแล้วสำหรับเก็บข้อมูลผู้ใช้ที่ยืนยันตัวตนแล้วสำหรับเวิร์กโฟลว์ n8n