petersalomonsen / wasm-git

GIT for nodejs and the browser using https://libgit2.org compiled to WebAssembly with https://emscripten.org
Other
632 stars 36 forks source link

Is it possible to push to a github repo? #72

Open iliakan opened 1 year ago

iliakan commented 1 year ago

Let's say we cloned a (public) github repository.

Is there a way to push there?

The only problem I see is credentials (reading can be public, writing - cannot). Any other issues?

For credentials, let's say, we're using our proxy (we have to do so anyway due to same-origin policy). Maybe we can use a Github App to get permissions for a repo, and then add these credentials to push requests (basically add auth tokens to requests)?

nikitavoloboev commented 1 year ago

You can check this github proxy, it authorises the requests and lets you git push too. I assume something similar would work with wasm-git too.

petersalomonsen commented 1 year ago

You can also alter the XMLHttpRequest.prototype.open in the worker to set the request header with bearer token or basic auth. This is how I do it in WebAssembly Music:

XMLHttpRequest.prototype._open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url, async, user, password) {
  this._open(method, url, async, user, password);
  this.setRequestHeader('Authorization', `Bearer ${accessToken}`);
  lastHttpRequest = this;
}

https://github.com/petersalomonsen/javascriptmusic/blob/master/wasmaudioworklet/wasmgit/wasmgitworker.js#L31