Skip to content

Commit da2abcb

Browse files
authored
Merge pull request #575 from janithjay/main
fix(browser): parse scim2 responses with non-standard json content-types
2 parents b7fac26 + 83c0597 commit da2abcb

4 files changed

Lines changed: 341 additions & 134 deletions

File tree

‎.changeset/wicked-ghosts-swim.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@asgardeo/browser': patch
3+
---
4+
5+
Fix SCIM2 responses (`/scim2/Me`, `/scim2/Schemas`, and related organization/profile API calls) not being parsed as JSON.
6+
7+
`FetchHttpClient` only treated a response as JSON when its `Content-Type` header was exactly `application/json`. Asgardeo's SCIM2 endpoints respond with `Content-Type: application/scim+json`, which didn't match, so the response body was returned as raw, unparsed text instead of a parsed object. This caused the user profile to render incorrectly (missing fields, or falling back to a partial ID-token-derived profile) or crash with `TypeError: schemas.forEach is not a function`.
8+
9+
The content-type check now correctly matches `application/json` and any subtype ending in `+json` (e.g. `application/scim+json`), while still treating non-document JSON formats like `application/geo+json-seq` as text (since those aren't parseable as a single JSON document).

‎packages/browser/src/FetchHttpClient.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ export class FetchHttpClient extends HttpClient {
9999
} as Partial<HttpError>);
100100
}
101101

102-
const contentType: string = fetchResponse.headers.get('content-type') ?? '';
103-
const responseData: T = contentType.includes('application/json')
104-
? await fetchResponse.json()
105-
: ((await fetchResponse.text()) as any);
102+
const contentType: string = (fetchResponse.headers.get('content-type') ?? '').split(';')[0].trim().toLowerCase();
103+
const isJson: boolean = contentType === 'application/json' || contentType.endsWith('+json');
104+
const responseData: T = isJson ? await fetchResponse.json() : ((await fetchResponse.text()) as any);
106105

107106
const responseHeaders: Record<string, string> = {};
108107
fetchResponse.headers.forEach((value: string, key: string) => {

0 commit comments

Comments
 (0)