fix: build redirect endpoint URLs locally instead of making HTTP requests#358
fix: build redirect endpoint URLs locally instead of making HTTP requests#358gjtorikian merged 3 commits intomainfrom
Conversation
…ests getAuthorizationUrl() and getLogoutUrl() on SSO and UserManagement were making real HTTP requests to redirect endpoints, receiving HTML instead of JSON, and throwing a TypeError via fromArray(null). These methods now construct the URL client-side and return a string, matching the Python and .NET SDKs. Also fixes decodeResponse() to throw ApiException on non-JSON success bodies instead of silently returning null, and updates the V5 migration guide to reflect the correct behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR fixes
Confidence Score: 4/5Safe to merge after correcting the migration guide's getProfileAndToken() example, which shows non-existent named arguments that would cause a PHP fatal error. The core fix is correct and well-tested: URLs are built locally, the empty-query guard prevents a bare docs/V5_MIGRATION_GUIDE.md — the getProfileAndToken() example needs to be corrected Important Files Changed
Sequence DiagramsequenceDiagram
participant App
participant SSO/UM as SSO / UserManagement
participant HttpClient
participant WorkOS as WorkOS API
Note over App,WorkOS: Before fix — HTTP request made
App->>SSO/UM: getAuthorizationUrl(...)
SSO/UM->>HttpClient: request(GET, sso/authorize, ...)
HttpClient->>WorkOS: HTTP GET /sso/authorize
WorkOS-->>HttpClient: 302 HTML redirect page
HttpClient->>HttpClient: decodeResponse() → null
HttpClient-->>SSO/UM: null
SSO/UM-->>App: TypeError (fromArray(null))
Note over App,WorkOS: After fix — URL built locally
App->>SSO/UM: getAuthorizationUrl(...)
SSO/UM->>HttpClient: requireClientId()
HttpClient-->>SSO/UM: "client_123"
SSO/UM->>HttpClient: buildUrl(sso/authorize, query, options)
HttpClient->>HttpClient: resolveUrl() + http_build_query()
HttpClient-->>SSO/UM: "https://api.workos.com/sso/authorize?..."
SSO/UM-->>App: string URL
|
Summary
getAuthorizationUrl()andgetLogoutUrl()on SSO and UserManagement were making real HTTP requests to redirect endpoints, receiving HTML instead of JSON, and throwing aTypeErrorviafromArray(null). These methods now construct the URL client-side and return astring, matching the Python and .NET SDKs.HttpClient::decodeResponse()now throwsApiExceptionon non-JSON success bodies instead of silently returningnull, so any future misuse surfaces a clear error.HttpClient::buildUrl()respectsRequestOptions::$baseUrloverrides.Test plan
script/cipasses (php-cs-fixer, PHPStan, PHPUnit 233 tests)Closes #357