NetSparkleUpdater / NetSparkle

NetSparkle is a C#, cross-platform, highly-configurable software update framework with pre-built UI for .NET developers compatible with .NET 4.6.2/.NET 6+, WinForms, WPF, and Avalonia; uses Ed25519 signatures. View basic usage here in the README and try the samples for yourself.
https://netsparkleupdater.github.io/NetSparkle/
MIT License
606 stars 84 forks source link

Pass credentials for downloading appcast,installer,... #352

Closed meuper closed 1 year ago

meuper commented 2 years ago

Hello, my appcast.xml, installer and so on are hosted on a password restricted nexus repository. Is it possible to pass credentials for that?

Deadpikle commented 2 years ago

Hi @meuper,

You can implement your own IUpdateDownloader and IAppCastDataDownloader for this!

https://github.com/NetSparkleUpdater/NetSparkle/blob/42f21fdc8e8ab1af9ba747788b9e918e5d20d4fb/src/NetSparkle/SparkleUpdater.cs#L421-L430

Easiest thing for you to do is probably to just grab the current implementations and create your own versions based on those.

meuper commented 2 years ago

@Deadpikle thank you for the quick reply. I think it would be easier to customize the http client if there where a method to create it. So we could only override that method to add a header or something.

As an example, add following method and change http client creation to

HttpClient httpClient = CreateHttpClient(handler);
protected HttpClient CreateHttpClient()
{
    return CreateHttpClient(null);
}
protected HttpClient CreateHttpClient(HttpClientHandler handler)
{
    HttpClient httpClient;
    // use HttpClient synchronously: https://stackoverflow.com/a/53529122/3938401
    if (handler != null)
    {
        httpClient = new HttpClient(handler);
    }
    else
    {
        httpClient = new HttpClient();
    }
    if (_base64Token != null)
    {
        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _base64Token);
    }
    return httpClient;
}
Deadpikle commented 1 year ago

Hi @meuper,

I have followed your suggestion in 2.1.3-preview20220927001. There are now virtual methods in WebClientFileDownloader, WebRequestAppCastDataDownloader, and ReleaseNotesGrabber that should make this easier for you. Can you let me know if this helps you? :) Thanks!

meuper commented 1 year ago

@Deadpikle 2.1.3-preview20220927001 works for me and makes it much easier to use. Thanks :)

Deadpikle commented 1 year ago

Rolling out now via CI/CD in version 2.1.3! Thank you again!

meuper commented 1 year ago

@Deadpikle It seems the preprocessor conditional removes the CreateHttpClient method from the class WebRequestAppCastDataDownloader

Deadpikle commented 1 year ago

@meuper #386