Skip to content

Add support for bearer token auth with Composer registries#28

Merged
JamieMagee merged 2 commits intodependabot:mainfrom
hype09:paik/composer-token-auth
Feb 9, 2026
Merged

Add support for bearer token auth with Composer registries#28
JamieMagee merged 2 commits intodependabot:mainfrom
hype09:paik/composer-token-auth

Conversation

@hype09
Copy link
Copy Markdown
Contributor

@hype09 hype09 commented Feb 7, 2026

This PR follows from the discussion at dependabot/dependabot-core#12946.

Some composer registries, ex. packages.shopware.com, only support Bearer authentication. Dependabot currently only supports Basic Auth.

I have added a token field to the credentials which takes precedence over basic auth when a token is set and not empty.

The added tests all run on my machine, and I have tested my changes using dependabot/cli with the following configuration:

# config.yml
job:
    package-manager: composer
    allowed-updates:
      - update-type: all
    source:
        provider: github
        repo: <my-repo>
        directory: /
credentials:
  - type: git_source
    host: github.com
    username: x-access-token
    password: $GITHUB_TOKEN

  - type: composer_repository
    registry: packages.shopware.com
    token: $SHOPWARE_TOKEN

I ran it with a locally built image of the proxy as follows:

#!/bin/bash
dependabot update \
    --proxy-image dependabot-proxy-local:dev \
    -f config.yml

The log output shows that authentication has worked for packages.shopware.com:

proxy | 2026/02/07 08:24:03 [012] GET https://packages.shopware.com:443/packages.json
proxy | 2026/02/07 08:24:03 [012] * authenticating composer registry request (host: packages.shopware.com)
proxy | 2026/02/07 08:24:06 [012] 200 https://packages.shopware.com:443/packages.json

Disclaimer: My experience with Go is somewhat limited, so if there are more idiomatic ways to solve things, I'd be happy to learn! Also, I've seen a few places in dependabot-core where Composer uses basic auth. I'm unsure if we should add token support there, too? If that's the case, I'd be happy so work on a PR.

Copy link
Copy Markdown

@ahtizazhasnain-hue ahtizazhasnain-hue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M

Comment thread internal/handlers/composer.go Outdated
@@ -92,7 +94,11 @@ func (h *ComposerHandler) HandleRequest(req *http.Request, ctx *goproxy.ProxyCtx
}

logging.RequestLogf(ctx, "* authenticating composer registry request (host: %s)", req.URL.Hostname())
Copy link
Copy Markdown
Member

@JamieMagee JamieMagee Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message doesn't distinguish between bearer and basic auth. The NPM handler does this (host: %s, basic auth) vs (host: %s, token auth), and it's genuinely useful when debugging why a registry is rejecting credentials. Could you split the log line so it says which auth method is being used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me 👍

@JamieMagee
Copy link
Copy Markdown
Member

Thanks for this change! Other than the log message, this looks good.

Also, I've seen a few places in dependabot-core where Composer uses basic auth. I'm unsure if we should add token support there, too? If that's the case, I'd be happy so work on a PR.

Nope, shouldn't be needed. The original architecture passed credentials directly to dependabot-core, but that hasn't been the case since the proxy came along. You can technically still pass credentials directly, but if you look at github/dependabot-action or dependabot/cli you'll see credentials go to the proxy and secrets are never exposed to dependabot-core.

@JamieMagee JamieMagee merged commit 4aacc43 into dependabot:main Feb 9, 2026
90 checks passed
@hype09 hype09 deleted the paik/composer-token-auth branch February 9, 2026 22:33
@hype09
Copy link
Copy Markdown
Contributor Author

hype09 commented Feb 10, 2026

I'm trying to get this running now, with the following config:

version: 2
registries:
  shopware-packages:
    type: composer-repository
    url: packages.shopware.com
    token: ${{secrets.SHOPWARE_TOKEN}}

But I'm getting the following error message:

The property '#/registries/shopware-packages/' of type object did not match one or more of the required schemas

I couldn't find where the schema for the config is defined, do we need to update it, too, to support token?

Or is perhaps my config wrong? :D

@jumoog
Copy link
Copy Markdown

jumoog commented Feb 10, 2026

I don't think it will be deployed immediately.

@hype09
Copy link
Copy Markdown
Contributor Author

hype09 commented Feb 19, 2026

I think the issue I am encountering this not because of deployment, but rather some config validation step?

registries:
  shopware-packages:
    type: composer-repository
    url: packages.shopware.com
    token: ${{secrets.SHOPWARE_TOKEN}}

See the screenshot below:

image

Do you know if there's a schema defined somewhere that is used for validation?

@JamieMagee
Copy link
Copy Markdown
Member

JamieMagee commented Feb 19, 2026

@hype09 @jumoog There were some internal changes required to update the schema validation. I am deploying the changes now

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.

4 participants