Authentication Error: Authentication Required

Trying to clone a repo using go-git, below is the code that I wrote. I'm using BasicAuth from provided "http" package in go-git.

r, err := git.PlainClone(directory, false, &git.CloneOptions{
		Auth: &http.BasicAuth{
			Username: username,
			Password: password,
		},
		URL:      url,
		Progress: os.Stdout,
	})

Also tried using in-memory clone but it also gives same error :

r, err := git.Clone(storer, fs, &git.CloneOptions{
		URL:  repository,
		Auth: &http.BasicAuth{
			Username: username,
			Password: password,
		},
	})

the error simply says "authentication required" . This is the same method all official examples are also following. Not sure if I am missing anything here ?