roots / trellis

WordPress LEMP stack with PHP 8.2, Composer, WP-CLI and more
https://roots.io/trellis/
MIT License
2.51k stars 607 forks source link

Composer Authentication: Add support for `bearer`, `gitlab-oauth`, `gitlab-token`, `github-oauth` and `bitbucket-oauth` principles #1413

Closed tangrufus closed 1 year ago

tangrufus commented 2 years ago

Add support for bearer gitlab-oauth, gitlab-token, github-oauth and bitbucket-oauth principles

Principle (type) Supported?
http-basic :white_check_mark: old feature
Inline http-basic :x: use http-basic instead
HTTP Bearer (bearer) :white_check_mark:
Custom header :x: composer doesn't support setting it in non-interactive mode
gitlab-oauth :white_check_mark:
gitlab-token :white_check_mark:
github-oauth :white_check_mark:
bitbucket-oauth :white_check_mark:

Breaking Changes

Note Breaking changes have been removed. See: https://github.com/roots/trellis/pull/1413#issuecomment-1228352480

This PR contains a breaking change. type is now required in composer_authentications.

For example:

---
composer_authentications:
  - { type: http-basic, hostname: http-basic.com, username: http-basic-username, password: http-basic-password }
  - { type: http-basic, hostname: second.http-basic.com/without-password, username:  second-http-basic-username }

  - { type: bearer, hostname: bearer.com, token: bearer-token }
  - { type: bearer, hostname: second.bearer.com/abc/def, token:  second-bearer-token }

  - { type: gitlab-oauth, hostname: gitlab.com, token: gitlab-com-oauth-token }
  - { type: gitlab-oauth, hostname: gitlab.oauth.org, token: gitlab-oauth-org-token }

  - { type: gitlab-token, hostname: gitlab.com, token: gitlab-com-token-token }
  - { type: gitlab-token, hostname: gitlab.token.org, token: gitlab-token-org-token }

  - { type: github-oauth, hostname: github.com, token: githubcomtoken }
  - { type: github-oauth, hostname: you.most.likely.set.this.to.github-com.example, token: youmostlikelysetthistogithubcomexampletoken }

  - { type: bitbucket-oauth, hostname: bitbucket.org, consumer_key: bitbucket-org-consumer-key, consumer_secret: bitbucket-org-consumer-secret }
  - { type: bitbucket-oauth, hostname: private-bitbucket.com, consumer_key: private-bitbucket-com-consumer-key, consumer_secret: private-bitbucket-com-consumer-secret }

The above example results in the following auth.json:

{
    "http-basic": {
        "http-basic.com": {
            "username": "http-basic-username",
            "password": "http-basic-password"
        },
        "second.http-basic.com/without-password": {
            "username": "second-http-basic-username",
            "password": ""
        }
    },
    "bitbucket-oauth": {
        "bitbucket.org": {
            "consumer-key": "bitbucket-org-consumer-key",
            "consumer-secret": "bitbucket-org-consumer-secret"
        },
        "private-bitbucket.com": {
            "consumer-key": "private-bitbucket-com-consumer-key",
            "consumer-secret": "private-bitbucket-com-consumer-secret"
        }
    },
    "bearer": {
        "bearer.com": "bearer-token",
        "second.bearer.com/abc/def": "second-bearer-token"
    },
    "gitlab-oauth": {
        "gitlab.com": "gitlab-com-oauth-token",
        "gitlab.oauth.org": "gitlab-oauth-org-token"
    },
    "gitlab-token": {
        "gitlab.com": "gitlab-com-token-token",
        "gitlab.token.org": "gitlab-token-org-token"
    },
    "github-oauth": {
        "github.com": "githubcomtoken",
        "you.most.likely.set.this.to.github-com.example": "youmostlikelysetthistogithubcomexampletoken"
    }
}

github-oauth was supported in v0.9.3 but removed in v0.9.6


See also:

tangrufus commented 2 years ago

Defaults type to http-basic. No more breaking changes.

For example:

composer_authentications:
  - { hostname: default-type.com, username: default-type-username, password: default-type-password }
  - { hostname: second.default-type.com/without-password, username:  second-default-type-username }

  - { type: http-basic, hostname: http-basic.com, username: http-basic-username, password: http-basic-password }
  - { type: http-basic, hostname: second.http-basic.com/without-password, username:  second-http-basic-username }

  - { type: bearer, hostname: bearer.com, token: bearer-token }
  - { type: bearer, hostname: second.bearer.com/abc/def, token:  second-bearer-token }

  - { type: gitlab-oauth, hostname: gitlab.com, token: gitlab-com-oauth-token }
  - { type: gitlab-oauth, hostname: gitlab.oauth.org, token: gitlab-oauth-org-token }

  - { type: gitlab-token, hostname: gitlab.com, token: gitlab-com-token-token }
  - { type: gitlab-token, hostname: gitlab.token.org, token: gitlab-token-org-token }

  - { type: github-oauth, hostname: github.com, token: githubcomtoken }
  - { type: github-oauth, hostname: you.most.likely.set.this.to.github-com.example, token: youmostlikelysetthistogithubcomexampletoken }

  - { type: bitbucket-oauth, hostname: bitbucket.org, consumer_key: bitbucket-org-consumer-key, consumer_secret: bitbucket-org-consumer-secret }
  - { type: bitbucket-oauth, hostname: private-bitbucket.com, consumer_key: private-bitbucket-com-consumer-key, consumer_secret: private-bitbucket-com-consumer-secret }

The above example results in the following auth.json:

{
    "http-basic": {
        "default-type.com": {
            "username": "default-type-username",
            "password": "default-type-password"
        },
        "second.default-type.com/without-password": {
            "username": "second-default-type-username",
            "password": ""
        },
        "http-basic.com": {
            "username": "http-basic-username",
            "password": "http-basic-password"
        },
        "second.http-basic.com/without-password": {
            "username": "second-http-basic-username",
            "password": ""
        }
    },
    "bitbucket-oauth": {
        "bitbucket.org": {
            "consumer-key": "bitbucket-org-consumer-key",
            "consumer-secret": "bitbucket-org-consumer-secret"
        },
        "private-bitbucket.com": {
            "consumer-key": "private-bitbucket-com-consumer-key",
            "consumer-secret": "private-bitbucket-com-consumer-secret"
        }
    },
    "bearer": {
        "bearer.com": "bearer-token",
        "second.bearer.com/abc/def": "second-bearer-token"
    },
    "gitlab-oauth": {
        "gitlab.com": "gitlab-com-oauth-token",
        "gitlab.oauth.org": "gitlab-oauth-org-token"
    },
    "gitlab-token": {
        "gitlab.com": "gitlab-com-token-token",
        "gitlab.token.org": "gitlab-token-org-token"
    },
    "github-oauth": {
        "github.com": "githubcomtoken",
        "you.most.likely.set.this.to.github-com.example": "youmostlikelysetthistogithubcomexampletoken"
    }
}