.NETCore HttpClient DelegatingHandler for OVH API Credentials.
This delegating handler decouples the proprietary authentication mechanism from a given api implementation. It allows to use any HttpClient/IHttpClientFactory rest client to consume OVH API. Doing so, unit tests are more easy to do than with the official implementation.
This project does not aim at providing a strongly-typed rest client. OVH API changes over the time, is not the same on all regions and the specification of the api is hidden in a yet another proprietary api specification format which make difficult to maitain an up to date package.
You only need to add the delegating handler by calling AddOVHCredentials.
To get your credentials, follow the user guide.
varprovider=newServiceCollection().AddHttpClient("ovh", c =>c.BaseAddress=newUri("https://eu.api.ovh.com/1.0")).AddOVHCredentials(options =>{// you are free to use whatever you are used to to configure the handleroptions.ApplicationKey="";options.ApplicationSecret="";options.ConsumerKey="";}).Services.BuildServiceProvider();varhttpClientFactory=provider.GetRequiredService<IHttpClientFactory>();varhttpClient=httpClientFactory.CreateClient("ovh");awaithttpClient.GetAsync("/me");This sample uses Refit library.
classProgram{staticasyncTaskMain(string[]args){varprovider=newServiceCollection().AddRefitClient<IMe>().ConfigureHttpClient(c =>c.BaseAddress=newUri("https://eu.api.ovh.com/1.0"))// as credentials are time based, polly (if used) should be placed before credentials.AddTransientHttpErrorPolicy(policyBuilder =>policyBuilder.RetryAsync(2))// configure the client with ovh credentials.AddOVHCredentials(options =>{// you are free to use whatever you are used to to configure the handleroptions.ApplicationKey="";options.ApplicationSecret="";options.ConsumerKey="";}).Services.BuildServiceProvider();varclient=provider.GetRequiredService<IMe>();varme=awaitclient.Me();Console.WriteLine($"Welcome, {me.firstname}");}publicinterfaceIMe{[Get("/me")]publicTask<PartialMe>Me();}publicclassPartialMe{publicstringfirstname{get;set;}publicstringname{get;set;}}}The ApiTester sample application shows how to retrieve the consumer key, if needed.