Support for private GitHub repos
derech1e opened this issue · 7 comments
Hey, there is currently no support for private Github-Repositorys.
It is possible to add this feature?
Thank you in advance.
Hey. There is, you just need to pass in your own HttpClient
that has the authentication header set.
Okay. I've tested it, but it didn't worked. A 404 is displayed, when I try to update.
I think it is not possible, to access the browser_download_url
via an access_token
. I think also it only works when you try to download the octet-stream
directly from https://api.github.com/repos/NAME/REPO/releases/assets/ID
.
Hmmm, that may very well be true. If that's the case, it should probably be possible to change this line so that it uses url
instead of browser_download_url
:
Onova/Onova/Services/GithubPackageResolver.cs
Line 101 in ef20bdb
Can you try it and see?
So I changed the the line to this:
var assetUrl = assetJson.GetProperty("url").GetString();
and that works. But when it comes to the actual download it fails.
This error arise:
System.IO.InvalidDataException: End of Central Directory record could not be found.
at System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory()
at System.IO.Compression.ZipArchive.Init(Stream stream, ZipArchiveMode mode, Boolean leaveOpen)
at System.IO.Compression.ZipArchive..ctor(Stream stream, ZipArchiveMode mode, Boolean leaveOpen, Encoding entryNameEncoding)
at System.IO.Compression.ZipFile.Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding)
at Onova.Services.ZipPackageExtractor.ExtractPackageAsync(String sourceFilePath, String destDirPath, IProgress`1 progress, CancellationToken cancellationToken)
at Onova.UpdateManager.PrepareUpdateAsync(Version version, IProgress`1 progress, CancellationToken cancellationToken)
at ...
I think you need to define a special or new HttpClient here:
Onova/Onova/Internal/HttpClientEx.cs
Line 85 in ef20bdb
So for me it worked to add new headers here:
Onova/Onova/Internal/HttpClientEx.cs
Line 29 in ef20bdb
I copy and pasted the method and added:
client.DefaultRequestHeaders.Add("Authorization", "token TOKEN");
client.DefaultRequestHeaders.Add("Accept", "application/octet-stream");
Then I upated the HttpClient: using var response = await GetPrivateDownloadSingleton().GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
I tested that way and it worked. But I think that is not the best way to solve the problem. When you add the Accept Header here:
Onova/Onova/Internal/HttpClientEx.cs
Line 29 in ef20bdb
it won't work, because he try to parse a string (json) as a octet-stream first before he actual download the ZIP.
In that case, the Accept
header needs to be added here:
Onova/Onova/Internal/HttpClientEx.cs
Line 85 in ef20bdb
The GetAsync
will have to be replace with SendAsync
and a custom HttpRequestMessage
.
Potentially setting it to Accept: */*
if that works.
I tested it and it works only this way:
var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.Add("Accept", "application/octet-stream");
using var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
Can you make a PR with this?