Skip to content

Commit f099ab6

Browse files
committed
Add extended JSON handling in OIDC API Proxy to include OIDC claims in specific requests
1 parent 3cb16c7 commit f099ab6

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

endpoints/helpers/endpoint.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,27 @@ def check_app_streaming_request(request: werkzeug.Request) -> Tuple[bool, bool]:
131131
return is_app_call, is_stream
132132

133133

134+
def get_extended_json(request: werkzeug.Request, claims: dict) -> Any | None:
135+
if not request.is_json:
136+
return None
137+
138+
json = request.get_json()
139+
if request.method.lower() not in ["post"]:
140+
return json
141+
if request.path not in ["/chat-messages", "/workflows/run"]:
142+
return json
143+
144+
if isinstance(json, dict) and "inputs" in json:
145+
for claim in claims:
146+
try:
147+
key = f"__oidc_{claim}"
148+
json["inputs"][key] = claims[claim]
149+
except Exception:
150+
pass
151+
152+
return json
153+
154+
134155
def replace_user_params(
135156
user: str,
136157
args: werkzeug.datastructures.MultiDict[str, str],

endpoints/oidc_api_proxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dify_plugin import Endpoint
55
from werkzeug import Request, Response
66

7-
from endpoints.helpers.endpoint import OidcApiProxyErrorResponse, proxy_response, replace_user_params
7+
from endpoints.helpers.endpoint import OidcApiProxyErrorResponse, get_extended_json, proxy_response, replace_user_params
88
from endpoints.helpers.oidc import OpenIDConnectDiscoveryProvider
99

1010

@@ -64,7 +64,7 @@ def _invoke(self, r: Request, values: Mapping, settings: Mapping) -> Response:
6464

6565
# prepare params, json and data
6666
params = r.args
67-
json = r.get_json() if r.is_json else None
67+
json = get_extended_json(r, oidc_claims)
6868
data = r.form
6969

7070
# replace user params

0 commit comments

Comments
 (0)