-
|
I'm trying to implement the BasicAuth method for HTTP cloning from Github using a Access Token by following the example code, but whatever I try I always get the error This is the function that returns the AuthMethod with my Github PAT: func HttpTokenAuth(token string) transport.AuthMethod {
return &githttp.BasicAuth{
Username: "oauth2", // can be anything except an empty string
Password: token,
}
}In my func CloneRepository(path, url, ref string, skipTLSVerify bool, proxyOpts transport.ProxyOptions, auth transport.AuthMethod, cloneSubmodules bool) (*git.Repository, error) {
err := os.MkdirAll(path, filesystem.PermDir)
if err != nil {
return nil, fmt.Errorf("failed to create directory %s: %w", path, err)
}
opts := &git.CloneOptions{
RemoteName: RemoteName,
URL: url,
SingleBranch: true,
ReferenceName: plumbing.ReferenceName(ref),
Tags: git.NoTags,
Auth: auth,
}
if cloneSubmodules {
opts.RecurseSubmodules = git.DefaultSubmoduleRecursionDepth
}
if IsSSH(url) {
err = addToKnownHosts(url)
if err != nil {
return nil, fmt.Errorf("failed to add host to known_hosts: %w", err)
}
opts.URL = convertSSHUrl(url)
} else {
opts.InsecureSkipTLS = skipTLSVerify
if proxyOpts != (transport.ProxyOptions{}) {
opts.ProxyOptions = proxyOpts
}
}
return git.PlainClone(path, false, opts)
}But I always get the error |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I'm having the same issue, but for pulling a private repository... Were you ever able to figure this out? Edit: |
Beta Was this translation helpful? Give feedback.
For me the issue was that I had forgotten that I had some Git submodules in my repository that had a SSH clone url configured but I tried to clone the main repository via HTTP and basic auth.
After changing all submodule urls to http it was working.