Isomorphic-git: Seeing 401 unauthorized errors when trying to clone private repo

Created on 29 Jun 2020  路  3Comments  路  Source: isomorphic-git/isomorphic-git

Hi! Firstly thanks for creating this library :)

I'm new to this and unsure if I'm doing something wrong here, but I'm constantly seeing 401 errors when trying to clone a private repo of mine.

Here's what I'm trying (in Chrome 83 on OSX 10.15):

<script src="https://unpkg.com/@isomorphic-git/lightning-fs"></script>
<script src="https://unpkg.com/isomorphic-git"></script>
<script type="module">
    import http from 'https://unpkg.com/isomorphic-git@beta/http/web/index.js'
    window.http = http;
</script>
let fs = new LightningFS('fs');
let pfs = fs.promises;
let dir = "/data";

await pfs.mkdir(dir);
await pfs.readdir(dir);

await git.clone(
  {
    fs: fs,
    http: window.http,
    dir: dir,
    corsProxy: 'https://cors.isomorphic-git.org',
    url: 'https://github.com/pickledish/private-repo',
    ref: 'master',
    username: 'pickledish',
    password: "valid-personal-access-token-123",
    singleBranch: true,
    depth: 10,
  }
);



md5-2468e776d0c419bbf668da6ad712f456



GET https://cors.isomorphic-git.org/github.com/pickledish/private-repo/info/refs?service=git-upload-pack 401

I've verified that I'm able to pull public repos this exact way ^ without issue, and also verified via git clone https://github.com/pickledish/private-repo (in bash) that this particular username/token combo works, so I'm not sure where to go from here. If the answer is just to read some documentation, happy to read it, but haven't been able to find anything about this in my searches.

Thanks in advance, lmk if I can add any more detail!

Most helpful comment

I am able to this using the following url

https://pickledish:[email protected]/pickledish/private-repo

and removing the username and password fields like this

await git.clone(
  {
    fs: fs,
    http: window.http,
    dir: dir,
    corsProxy: 'https://cors.isomorphic-git.org',
    url: 'https://pickledish:[email protected]/pickledish/private-repo,
    ref: 'master',
    singleBranch: true,
    depth: 10,
  }
);

Not sure if it's the best way to do it, but it should be ok.

All 3 comments

I am able to this using the following url

https://pickledish:[email protected]/pickledish/private-repo

and removing the username and password fields like this

await git.clone(
  {
    fs: fs,
    http: window.http,
    dir: dir,
    corsProxy: 'https://cors.isomorphic-git.org',
    url: 'https://pickledish:[email protected]/pickledish/private-repo,
    ref: 'master',
    singleBranch: true,
    depth: 10,
  }
);

Not sure if it's the best way to do it, but it should be ok.

Ah, wow good tip @koustubhg confirmed that worked for me too! I wonder what kind of bug was introduced here, wish I knew more JS 馃

Also encountered this bug today. But thanks to @koustubhg's solution, the workaround worked pretty well! 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aanavaneeth picture aanavaneeth  路  3Comments

chmac picture chmac  路  4Comments

jcubic picture jcubic  路  4Comments

juancampa picture juancampa  路  7Comments

stefan-guggisberg picture stefan-guggisberg  路  6Comments