From d760c1525fc2b213828cc27e0ffc0ee0ef99dc88 Mon Sep 17 00:00:00 2001 From: Abner <22141172+Silentely@users.noreply.github.com> Date: Fri, 1 Aug 2025 19:18:44 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Fix=20Giffgaff=20CSP=20and=20OAu?= =?UTF-8?q?th=20callback=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 Problems Fixed: 1. CSP violation blocking id.giffgaff.com API calls 2. OAuth callback URL parsing for giffgaff:// protocol ✨ Solutions Implemented: 1. CSP Configuration: - Added comprehensive Content-Security-Policy meta tag - Included id.giffgaff.com and publicapi.giffgaff.com domains - Fixed connect-src directive to allow OAuth token exchange 2. OAuth Callback Parsing: - Support for giffgaff://auth/callback/ protocol URLs - Backward compatibility with standard HTTP/HTTPS URLs - Regex-based parameter extraction for custom protocols - Enhanced debugging with console logs 3. User Interface Improvements: - Added callback URL format explanation - Clear examples of supported URL formats - Better placeholder text with actual example 🔍 Technical Details: - CSP now allows connections to all required Giffgaff domains - Callback parser handles both giffgaff:// and https:// protocols - Added proper URL decoding for extracted parameters 📋 Files Modified: - giffgaff_complete_esim.html: CSP config + callback parsing - Added GIFFGAFF_CSP_CALLBACK_FIX.md: Detailed fix documentation This resolves the CSP violation and enables proper OAuth flow. --- .gitignore | 4 +- GIFFGAFF_CSP_CALLBACK_FIX.md | 183 +++++++++++++++++++++++++++++++++++ giffgaff_complete_esim.html | 32 +++++- 3 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 GIFFGAFF_CSP_CALLBACK_FIX.md diff --git a/.gitignore b/.gitignore index f2cff9f..3d49977 100644 --- a/.gitignore +++ b/.gitignore @@ -104,4 +104,6 @@ dist/ .env.development .env.test Giffgaff-swap-esim.json -giffgaff.html \ No newline at end of file +giffgaff.html +Simyo-swap-esim.json +simyo.html diff --git a/GIFFGAFF_CSP_CALLBACK_FIX.md b/GIFFGAFF_CSP_CALLBACK_FIX.md new file mode 100644 index 0000000..445b8f1 --- /dev/null +++ b/GIFFGAFF_CSP_CALLBACK_FIX.md @@ -0,0 +1,183 @@ +# Giffgaff CSP和OAuth回调问题修复 + +## 🔍 问题描述 + +用户在使用Giffgaff eSIM工具时遇到两个关键问题: + +### 1. CSP (Content Security Policy) 违规 +``` +Refused to connect to 'https://id.giffgaff.com/auth/oauth/token' because it violates the following Content Security Policy directive: "connect-src 'self' https://api.qrserver.com https://appapi.simyo.nl https://api.giffgaff.com". +``` + +### 2. OAuth回调URL处理问题 +- 系统返回了 `giffgaff://auth/callback/?code=...&state=...` 格式的回调URL +- 原有代码只支持标准HTTP/HTTPS URL格式解析 + +## 🛠️ 修复方案 + +### 1. 修复CSP配置 + +**问题原因**: CSP的 `connect-src` 指令中缺少 `https://id.giffgaff.com` 域名 + +**修复方案**: 添加完整的CSP配置,包含所有必要的Giffgaff域名 + +```html + +``` + +### 2. 修复OAuth回调URL解析 + +**问题原因**: 原有代码只能处理标准HTTP/HTTPS URL,无法解析 `giffgaff://` 协议 + +**修复前代码**: +```javascript +const url = new URL(callbackUrl); +const code = url.searchParams.get('code'); +``` + +**修复后代码**: +```javascript +let code, state; + +if (callbackUrl.startsWith('giffgaff://')) { + // 处理giffgaff://协议的回调URL + const match = callbackUrl.match(/[?&]code=([^&]+)/); + const stateMatch = callbackUrl.match(/[?&]state=([^&]+)/); + code = match ? decodeURIComponent(match[1]) : null; + state = stateMatch ? decodeURIComponent(stateMatch[1]) : null; +} else { + // 处理标准HTTP/HTTPS URL + const url = new URL(callbackUrl); + code = url.searchParams.get('code'); + state = url.searchParams.get('state'); +} +``` + +### 3. 改进用户界面 + +**增加了回调URL格式说明**: +```html +
支持的格式:
+giffgaff://auth/callback/?code=...&state=...https://example.com/callback?code=...&state=...请复制包含 code 参数的完整URL
支持的格式:
+giffgaff://auth/callback/?code=...&state=...https://example.com/callback?code=...&state=...请复制包含 code 参数的完整URL