Skip to content

[fix/kw-bridge-interop] Fix KW bridge/IDP interoperability issues - #174

Merged
felix-schwarz merged 1 commit into
masterfrom
fix/kw-bridge-interop
Oct 20, 2026
Merged

felix-schwarz merged 1 commit into
masterfrom
fix/kw-bridge-interop

Conversation

@felix-schwarz

@felix-schwarz felix-schwarz commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Addresses the following issues:

Issue 1: only one user account can be added to the app

  • prompt=select_account is ignored by the KW IDP and no login UI is presented
  • existing session cookies then lead to immediate dismissal and the IDP returning tokens for the account last logged in (whose cookies are still present & valid)
  • fix: add parameter force_login=1 to auth requests to require the KW IDP to prompt for login, even if valid cookies for an account already exist

Issue 2: token refreshs fail & end in an infinite loop

  • the IDP returns a non-OAuth2/OIDC-standard response when the app requests a token refresh:
# RESPONSE --------------------------------------------------------
Method:      POST
URL:         https://content.kiteworks.com/oauth/token
Error:       -
Req Signals: networkAvailable
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
422 CLIENT ERROR
Content-Type: application/json; charset=UTF-8
Date: Tue, 29 Sep 2026 07:43:04 GMT
Content-Length: 114

{"errors":[{"code":"ERR_INVALID_PARAMETER","field":"scope","message":"String does not match expected pattern."}]}
  • an OAuth2-compliant response would have been f.ex. {"error": "invalid_request"}
  • the JSON format and lack of an error field falsely makes the SDK assume that the response is a successful refresh, resuming operation, running into Unauthorized responses immediately after and retrying to perform a token refresh, … in an infinite loop.
  • fixes:
    • the IDP took issue with the scope parameter of the refresh request containing offline_access. Removing it makes it return a valid OAuth2/OIDC response again
    • token refresh responses, in addition to checking for the response format (JSON) and the existence of an error field in the response, now also check for the existence of access_token, returning an error if it is not included either.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@jesmrec

jesmrec commented Oct 2, 2026

Copy link
Copy Markdown
Member

After a first look:

Issue 1: only one user account can be added to the app

fixed, after typing the URL of an already existing account, user is prompted to authentication ✅

Issue 2: token refreshs fail & end in an infinite loop

Infinite loop is fixed. Error message about incorrect scope is gone by removing offline_access from scope ✅

as stated above:

token refresh responses, in addition to checking for the response format (JSON) and the existence of an error field in the response, now also check for the existence of access_token, returning an error if it is not included either.

Before, we had a loop of errors (fixed), now, we have a singular error without a loop (you are now checking, not only the error existence but also the access_token to assure the session is still alive or not)

POST https://content.kiteworks.com/oauth/token HTTP/2.0 ← 422 application/json 122b 243ms

so, tokens not refreshed because an Unprocessable Content response. But, the request is correct. Am i missing something else? is that error something bad on the server/bridge side?

Finally, the errors instead of error typo in the response needs a fix from backend/idP/bridge side, i'd say.

@felix-schwarz

@felix-schwarz

Copy link
Copy Markdown
Collaborator Author

POST https://content.kiteworks.com/oauth/token HTTP/2.0 ← 422 application/json 122b 243ms

so, tokens not refreshed because an Unprocessable Content response. But, the request is correct. Am i missing something else? is that error something bad on the server/bridge side?

I'd say this issue has/had two sides to it:

  • client-side: an response with valid JSON but invalid content wasn't fully checked. Basically the return of valid JSON combined with the absence of an error field was interpreted as successful - which, in hindsight, is of course not sufficient. That was fixed by fully checking the response and providing details in the error message if those checks don't pass.
  • server-side: the response content is not valid under the OAuth spec, but seems to be an error in the internal format of the KW or bridge server instead. Even though the client can handle this now, I agree with you that this should be fixed on the server side, too. In addition, the 422 HTTP status code is - at the very least - uncommon. The OAuth2 spec seems to want a 400 or 401 HTTP status code for errors here.

@jesmrec

	- add parameter `force_login=1` to auth requests to require the KW IDP to prompt for login, even if valid cookies for an account already exist
	- check token response for existance of `access_token`, to account for invalid IDP responses that do not contain an `error` field, but not an `access_token` either
- OCAuthenticationMethodOpenIDConnect:
	- remove ` offline_access` from `scope` for refresh requests to KW IDPs, since these take issue with that being included in `scope`, responding with a non-standard response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants