|
@@ -331,13 +331,45 @@ serve(async (req) => {
|
|
|
|
|
|
|
|
// Handle OAuth callback
|
|
// Handle OAuth callback
|
|
|
if (action === 'callback') {
|
|
if (action === 'callback') {
|
|
|
- const success = url.searchParams.get('success')
|
|
|
|
|
- const userId = url.searchParams.get('user_id')
|
|
|
|
|
- const consumerKey = url.searchParams.get('consumer_key')
|
|
|
|
|
- const consumerSecret = url.searchParams.get('consumer_secret')
|
|
|
|
|
- const storeUrlParam = url.searchParams.get('store_url')
|
|
|
|
|
|
|
+ // WooCommerce sends OAuth credentials via POST request body
|
|
|
|
|
+ let success: string | null = null
|
|
|
|
|
+ let userId: string | null = null
|
|
|
|
|
+ let consumerKey: string | null = null
|
|
|
|
|
+ let consumerSecret: string | null = null
|
|
|
|
|
+ let storeUrlParam: string | null = null
|
|
|
|
|
+
|
|
|
|
|
+ // Parse POST body (WooCommerce sends form-urlencoded data)
|
|
|
|
|
+ if (req.method === 'POST') {
|
|
|
|
|
+ const contentType = req.headers.get('content-type') || ''
|
|
|
|
|
+
|
|
|
|
|
+ if (contentType.includes('application/x-www-form-urlencoded')) {
|
|
|
|
|
+ // Parse form-urlencoded body
|
|
|
|
|
+ const body = await req.text()
|
|
|
|
|
+ const params = new URLSearchParams(body)
|
|
|
|
|
+ success = params.get('success')
|
|
|
|
|
+ userId = params.get('user_id')
|
|
|
|
|
+ consumerKey = params.get('consumer_key')
|
|
|
|
|
+ consumerSecret = params.get('consumer_secret')
|
|
|
|
|
+ storeUrlParam = params.get('store_url')
|
|
|
|
|
+ } else if (contentType.includes('application/json')) {
|
|
|
|
|
+ // Fallback for JSON format
|
|
|
|
|
+ const body = await req.json()
|
|
|
|
|
+ success = body.success
|
|
|
|
|
+ userId = body.user_id
|
|
|
|
|
+ consumerKey = body.consumer_key
|
|
|
|
|
+ consumerSecret = body.consumer_secret
|
|
|
|
|
+ storeUrlParam = body.store_url
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Fallback to query parameters for GET requests
|
|
|
|
|
+ success = url.searchParams.get('success')
|
|
|
|
|
+ userId = url.searchParams.get('user_id')
|
|
|
|
|
+ consumerKey = url.searchParams.get('consumer_key')
|
|
|
|
|
+ consumerSecret = url.searchParams.get('consumer_secret')
|
|
|
|
|
+ storeUrlParam = url.searchParams.get('store_url')
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- console.log(`[WooCommerce] OAuth callback received - success: ${success}`)
|
|
|
|
|
|
|
+ console.log(`[WooCommerce] OAuth callback received - method: ${req.method}, success: ${success}, userId: ${userId}, hasKeys: ${!!consumerKey && !!consumerSecret}`)
|
|
|
|
|
|
|
|
if (success !== '1') {
|
|
if (success !== '1') {
|
|
|
console.error('[WooCommerce] OAuth rejected by user')
|
|
console.error('[WooCommerce] OAuth rejected by user')
|