fix(gitlab-oauth): preserve instanceUrl during OAuth callback flow #5026
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Error 401 and 400 when connecting Infisical self-hosted to GitLab self-hosted
Fixes #4569
Summary
This PR fixes an issue where the GitLab OAuth flow always defaulted to
https://gitlab.com, even when the user entered a self-hosted GitLab instance URL.During the OAuth redirect, the frontend serializes form data into
localStorage.However,
GitLabFormDatadid not explicitly definecredentials.instanceUrl, so the value was dropped during serialization/deserialization.As a result, the backend received no instanceUrl, and the OAuth exchange attempted to authenticate against gitlab.com, causing:
Root Cause
So when the frontend parses the callback payload using this type, Zod or TS validation strips unknown fields, including:
credentials.instanceUrl → removedThis matches our observation:
This means:
GitLabFormDatawas defined as:TGitLabConnection["credentials"]is a discriminated union, and in the OAuth case does not includeinstanceUrl.When the form data was stored in
localStorage, the missing field caused:credentials.instanceUrl→ undefinedThis caused all OAuth token exchanges to fail for self-hosted GitLab.
Fix
GitLabFormDatais rewritten to explicitly include the OAuth credential structure:This ensures:
instanceUrl/oauth/token.Testing
Before fix
Enter self-hosted GitLab URL:
https://ops-gitlab.example.comStart OAuth flow.
Callback logs show:
OAuth token exchange fails with 401.
After fix
Enter same self-hosted GitLab URL.
Start OAuth flow.
Callback logs show:
OAuth token exchange succeeds.
Connection is created.
Impact