Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

TokenAuth not working as expected #999

Closed
@mccurdyc

Description

@mccurdyc

I expect the following to clone a private repository using a personal access token.

...
	r, err := git.PlainClone(<directory>, false, &git.CloneOptions{
		URL:               <url>,
		RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
		Auth: &http.TokenAuth{
			Token: <personal_access_token>,
		},
	})
...
git clone https://github.com/mccurdyc/private-repo simple --recursive
error: unexpected client error: unexpected requesting "https://github.com/user/private-repo/info/refs?service=git-upload-pack" status code: 400

It looks like GitHub should support it:
https://blog.github.com/2012-09-21-easier-builds-and-deployments-using-git-over-https-and-oauth/

git clone https://<personal_access_token>@github.com/user/private-repo.git

As a side note, looks like the following work:

curl -H 'Authorization: Bearer <personal_access_token>' https://github.com/api/user/repos?visibility=private
curl -H 'Authorization: token <personal_access_token>' https://github.com/api/user/repos?visibility=private

The current implementation of TokenAuth in go-git does something similar to 2, except would only work for GitHub's API and not for cloning.

@smola added some context to this previously here

Also, this goplayground example aligns with the GitHub post in that you would send the token as username.

Next, you can simply use an OAuth token for the username and either a blank password or the string x-oauth-basic when cloning a repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions