Closed Stu-P closed 7 years ago
Awesome, great to hear @Stu-P! Yeah unfortunately we have had to move to a model where you will need to start the provider HTTP server and have it running on a port, so that we can talk to it. It was just too difficult to make the previous model work in a way that was compatible with .NET standard/core and work cross platform. Unfortunately I will not be able to add that method back in, which I am a bit sad about TBH.
When you say create a client and authenticate it, what do you mean? You should only need to start the HTTP server and then pass the localhost baseUri (with port) to Pact (where the HttpClient use to be passed). Also if you use provider state you will need to supply some middleware or an endpoint in that HTTP server to handle the state setup, which can be seen in the README (search for ProviderStateMiddleware)
Hopefully that helps. Keep me posted with how you go!
Below is what I was doing. I can spin up a self hosted ServiceStack service, but the service I am testing requires valid bearer token authentication. I must fetch a valid token from our dev oauth server, then add that on a HttpClient and pass that through. Otherwise I get a 401 on my requests.
I am not sure how to provide custom middlewares in ServiceStack which would remove our requirement for a valid token. I can do some research on it but it's not such a great library.
I guess I was hoping that if I can generate a valid bearer token, I could pass that in with the URL and the ruby implementation could accept that token and use it.
using (ServiceStackHost appHost = new AppHost())
{
using (var client = new HttpClient { BaseAddress = new Uri(BaseUri) })
{
appHost.Init()
.Start(BaseUri);
var authC = new UauthServiceAcProvider(new UauthServiceConfig { UauthApiKey = "{key}", UauthServiceUrl = "{authurl}", UseSystemProxy = false });
var jwtToken = authC.GetBearerToken().Result;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken);
pactVerifier
.ServiceProvider("DunsAllocateService", client)
.HonoursPactWith("DunsAllocateClient")
Unfortunately I don't know much about Service Stack, but we do have an example of token based authentication in the Samples in the repo (you may have already seen it). It uses Web API and OWIN though.
I would imagine that Service stack would have some extensibility hook like middleware.
Did you manage to get it working?
I did some digging around but it's beyond my skills. I'm trying to get one of my Devs to help me out.
Cheers for the 2.0 support!
I am trying to migrate my Pact tests over to the new 2.0 spec code but I am stuck on the Provider Verification.
I currently pass my own http client into the ServiceProvider but this appears to be no longer supported. We dont use OWIN, rather servicestack :( , so I needed to create a client and authenticate it myself rather than use the OWIN middleware in your samples.
Assuming it is no longer possible to use my own client due to the wrapping of the ruby code, would it be possible to support passing in a bearer token along with the service URL into the ServiceProvider?