CXuesong / WikiClientLibrary

/*🌻*/ Wiki Client Library is an asynchronous MediaWiki API client library targeting modern .NET platforms
https://github.com/CXuesong/WikiClientLibrary/wiki
Apache License 2.0
80 stars 16 forks source link

Include/add headers to WikiSite request #44

Open WesJM opened 5 years ago

WesJM commented 5 years ago

I'm trying to access a wiki that uses SAML authentication. Is there a method to include/add headers to a the WikiSite request?

CXuesong commented 5 years ago

You may want to derive your own implementation from WikiClient class, overriding WikiClient.CreateHttpRequestMessage. For example:

public class MyWikiClient : WikiClient
{

    // ... any class constructors here

    protected override HttpRequestMessage CreateHttpRequestMessage(string endPointUrl, WikiRequestMessage message)
    {
        var httpRequest = base.CreateHttpRequestMessage(endPointUrl, message);
        // Unconditionally adds a header to all the HTTP requests sent to the MediaWiki API endpoint.
        httpRequest.Headers.Add("Header", "Value");
        return httpRequest;
    }

}

Sorry about my lack of SAML authentication knowledge to properly address the situation in the code. While I'm looking for some introductory material for this, perhaps you might get some rough idea from the example above 🌚

Plus,

WesJM commented 5 years ago

No apologies...I truly appreciate all your work for the API. Thank you for the suggestion and example! :)

CXuesong commented 5 years ago

You are welcome. Anyway, I will try to keep this issue updated in future.