Conversation
Registers a PKCE OAuth method on the `gitlab` integration so browser login works without the external opencode-gitlab-auth plugin. Token storage and refresh scheduling are already owned by core; this supplies the authorize, refresh, and label implementations plus a self-managed instance URL field. The bundled client ID is an instance-owned, trusted application registered for the loopback redirect; GITLAB_OAUTH_CLIENT_ID overrides it for self-managed instances. GitLab matches redirect_uri exactly and also requires it on the refresh grant, so the callback port is fixed and EADDRINUSE reports a clear message. Workflow discovery now prefers the instance an OAuth credential was issued against over ambient defaults.
Owner
Author
|
Folding this into anomalyco#50422 instead of keeping a stacked PR — the OAuth commit is being pushed directly onto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue for this PR
Part of the GitLab Duo provider work. Stacked on anomalyco#50422.
Note
This PR is stacked on anomalyco#50422 (
restore-gitlab-discovery) and targets thatbranch, because both change
packages/core/src/plugin/provider/gitlab.ts.Please merge anomalyco#50422 first; this PR can then be retargeted to
v2.The diff below is only the OAuth commit on top of that branch.
Type of change
What does this PR do?
Adds a PKCE OAuth method to the built-in
gitlabintegration, so "Login withGitLab" works out of the box. Until now the only in-core auth methods were the
generic
key(personal access token) andenv(GITLAB_TOKEN) methods thatModelsDevPluginderives from the models.dev catalog; the OAuth path requiredthe external
opencode-gitlab-authplugin, which this makes unnecessary.
Core already owns credential storage, refresh scheduling, and merging
instanceUrl/apiKeyinto provider settings. This only supplies the piecescore cannot infer:
authorize,refresh,label, and a self-managed instanceURL form field. Implementation follows the existing in-core OAuth providers
(
poe.ts,digitalocean.ts,snowflake-cortex.ts):crypto.subtlefor PKCE,a loopback
node:httplistener,OauthCallbackPagefor the browser response,and
HttpClientfor the token exchange.GitLab specifics worth calling out:
redirect_uriexactly, so thelistener cannot use an ephemeral port like
poe.tsdoes. It is pinned tohttp://127.0.0.1:8080/callback;EADDRINUSEreports an actionable message(same approach as
digitalocean.ts, which pins 1456).redirect_urion the refresh grant. GitLab requires it there too, unlikemost providers.
invalid_grant. GitLab returns one opaque error for a reused orexpired code, a PKCE verifier mismatch, a redirect-URI mismatch, and a
confidential-client misconfiguration alike, so failures are annotated with the
redirect URI and client ID actually sent (never the code or verifier).
exists on gitlab.com.
GITLAB_OAUTH_CLIENT_IDoverrides it for self-managedinstances, and the docs explain registering one.
methodIDispkce, matching the credentials the external plugin alreadyissued, so existing logins keep resolving and refreshing.
Discovery from anomalyco#50422 now prefers the instance an OAuth credential was issued
against over ambient defaults, so a self-managed login discovers workflow models
from the right host instead of
GITLAB_INSTANCE_URL/gitlab.com.How did you verify your code works?
packages/core:bun typecheckclean.bun test test/plugin/— 322 pass, 0 fail across 42 files. That includes the4 discovery tests added by feat(core): restore GitLab workflow discovery and add OAuth login anomalyco/opencode#50422, which still pass unchanged.
test/plugin/provider-gitlab-oauth.test.ts(15 tests): method registrationshape, full authorize -> callback -> exchange against gitlab.com and a
self-managed URL, credential labelling, refresh (asserting
redirect_uriandthe stored instance), invalid/denied callbacks, failed exchanges preserving the
previously active connection,
EADDRINUSE, and theGITLAB_OAUTH_CLIENT_IDoverride.
One integration detail the tests surfaced: discovery subscribes to
Credential.Event.Switchedand resolves the credential, so it legitimately racesthe explicit
connection.resolveto refresh the same expired token. The refreshtest asserts on the matching token request rather than on a single queued reply.
Screenshots / recordings
Not a UI change; the new method appears as "Login with GitLab (OAuth)" in the
existing
/connectflow.Checklist