trellis icon indicating copy to clipboard operation
trellis copied to clipboard

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

Open tangrufus opened this issue 1 year ago • 1 comments

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

  • https://github.com/roots/trellis/pull/402
  • https://github.com/roots/trellis/commit/625ca3f1417476a29dc8bef85ba2d92044c0883e
  • https://github.com/roots/trellis/pull/491

See also:

  • https://getcomposer.org/doc/articles/authentication-for-private-packages.md#manually-editing-global-authentication-credentials
  • https://discourse.roots.io/t/composer-trellis-bedrock-private-composer-repositories/22831
  • https://discourse.roots.io/t/gitlab-private-repo-as-composer-package/20592
  • https://discourse.roots.io/t/private-or-commercial-wordpress-plugins-as-composer-dependencies/13247

tangrufus avatar Jul 26 '22 10:07 tangrufus

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"
    }
}

tangrufus avatar Aug 26 '22 10:08 tangrufus