Skip to content

Git over HTTPS rejects OAuth token unless username is 'oauth2'

Following https://docs.gitlab.com/ee/api/oauth2.html I generated an OAuth token with scope read_repository and write_repository

According to https://docs.gitlab.com/ee/integration/oauth_provider.html#authorized-applications this token should work for "read-write access to repositories on private projects using Git-over-HTTP"

However when I try git push with my username and the token as password, I get authentication error

$ git push
Username for 'https://gitlab.com': hickford
Password for 'https://hickford@gitlab.com': [token]
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://gitlab.com/coldnight/ci-test.git/'

Any ideas?

I tested a Personal access tokens with the same scope and it worked as expected.

OAuth token info from https://gitlab.com/oauth/token/info

{
    "resource_owner_id": 7962572,
    "scope": [
        "read_repository",
        "write_repository",
        "read_user"
    ],
    "expires_in": 6840,
    "application": {
        "uid": "d8a14250a4d1beacaad67dd6fabaab1e0408b581ca73ae4a76cc7170d3f8afd1"
    },
    "created_at": 1640989638,
    "scopes": [
        "read_repository",
        "write_repository",
        "read_user"
    ],
    "expires_in_seconds": 6840
}

Update: You must specify magic username oauth2. This is now documented at https://docs.gitlab.com/ee/api/oauth2.html#access-git-over-https-with-access-token

It would be an improvement to also accept the user's username (or ignore the username field entirely).

Edited by M Hickford