Skip to content

Commit 3762772

Browse files
cemalkilicRodriguespn
authored andcommitted
feat: handle oauth-protected-resource for edge functions
1 parent bf07635 commit 3762772

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

internal/start/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ EOF
489489
"KONG_DATABASE=off",
490490
"KONG_DECLARATIVE_CONFIG=/home/kong/kong.yml",
491491
"KONG_DNS_ORDER=LAST,A,CNAME", // https://github.com/supabase/cli/issues/14
492-
"KONG_PLUGINS=request-transformer,cors",
492+
"KONG_PLUGINS=request-transformer,cors,pre-function",
493493
fmt.Sprintf("KONG_PORT_MAPS=%d:8000", utils.Config.Api.Port),
494494
// Need to increase the nginx buffers in kong to avoid it rejecting the rather
495495
// sizeable response headers azure can generate

internal/start/templates/kong.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,28 @@ services:
228228
- /pooler/v2/
229229
plugins:
230230
- name: cors
231+
- name: request-transformer
232+
config:
233+
replace:
234+
headers:
235+
- "Authorization: {{ .BearerToken }}"
236+
- name: oauth-protected-resource
237+
_comment: "OAuth Protected Resource: /.well-known/oauth-protected-resource/functions/v1/<whatever> -> /functions/v1/<whatever>/.well-known/oauth-protected-resource"
238+
url: http://{{ .EdgeRuntimeId }}:8081/
239+
routes:
240+
- name: oauth-protected-resource
241+
strip_path: false
242+
paths:
243+
- /.well-known/oauth-protected-resource/functions/v1/
244+
plugins:
245+
- name: cors
246+
- name: pre-function
247+
config:
248+
access:
249+
- |
250+
local uri = kong.request.get_path()
251+
local new_uri = uri:gsub("^/.well%-known/oauth%-protected%-resource/functions/v1", "") .. "/.well-known/oauth-protected-resource"
252+
kong.service.request.set_path(new_uri)
231253
- name: mcp
232254
_comment: "MCP: /mcp -> http://studio:3000/api/mcp"
233255
url: http://{{ .StudioId }}:3000/api/mcp

0 commit comments

Comments
 (0)