RestSharp has recently released a major new version with a lot of breaking changes. One of the things to change was custom authenticators which now seem to be less obvious to use.
The documentation suggests creating a custom authenticator by inheriting from IAuthenticator
but this doesn’t seem to work and it’s necessary to inherit from AuthenticatorBase
instead. Possibly this is just a case of the documentation not having caught up with the code changes yet but in the meantime the below code demonstrates how to create a custom authenticator for adding an authentication query string parameter to a URL.
public class MetOfficeDataPointAuthenticator : AuthenticatorBase
{
public MetOfficeDataPointAuthenticator(string apiKey) : base(apiKey) { }
protected override ValueTask<Parameter> GetAuthenticationParameter(string apiKey)
=> new(new QueryParameter("key", apiKey));
}
0 Comments