Hey everyone! I'm trying to update a provider pact...
# pact-net
r
Hey everyone! I'm trying to update a provider pact test to add a fresh authorization token to all pact requests before they are replayed against the API. I've seen the WithCustomHeader method, but that seems to only add an authorization header, and not update an already present authorization header that might exist within the consumer pact json. Is there any workaround for this? Or is it generally understood to not include auth headers in the consumer json?
👍 1
m
howtoauth
s
Approaches to handling authentication in Pact tests: https://docs.pact.io/provider/handling_auth
m
There’s a couple of approaches ☝️
r
Thanks for the link! Looking at our options though, it still seems like using the custom header option is our best strategy. However, we are still running into the issue where the custom header option is not replacing the invalid token. Is this a bug?
m
How are you setting the header? Could you please share the code?
r
Setting the custom header? We're doing it through the .net nuget package method:
IPactVerifier pactVerifier = new PactVerifier(config);
pactVerifier
.ServiceProvider("Tenant.Api", new Uri(_tenantBaseUrl))
.WithPactBrokerSource(
new Uri("<https://avidxchange.pactflow.io>"),
options => options
.TokenAuthentication(_pactflowToken)
.PublishResults(
_providerVersion,
options => options.ProviderTags(_providerTags)
.ProviderBranch(_providerBranch)))
.WithProviderStateUrl(new Uri(_fixture.ServerUri, "/provider-states"))
.WithCustomHeader("Authorization", $"Bearer {tokenValue}")
.Verify();
Hey Matt, sorry for the super late ping, but did you get a chance to look at this?
m
oh sorry I missed this. It looks OK to me, might need to raise a bug report on the pact net github so it can be looked into in more detail