Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET Implementation of requestFilter seen on JS and GO version of Pact. #216

Closed
mmysliwiec opened this issue Oct 10, 2019 · 5 comments
Closed

Comments

@mmysliwiec
Copy link

I've read nice article about dealing with dynamically generated authentication: https://medium.com/dazn-tech/pact-contract-testing-dealing-with-authentication-on-the-provider-51fd46fdaa78

I have exactly the same problem. The article mentions about requestFilter solution which would be perfect for me. I can see the requestFilter is implemented only in JS and GO versions of Pact. Are you planning to implement this in .NET as well? It would be very helpful for dynamic authentication. Is there any other way to generate authentication header based on given request URL (per interaction rather than one header per contract file).

@akbhartiya
Copy link

akbhartiya commented Oct 10, 2019

you can your dynamically generated auth token to request as below
public async Task TestMyService()
{
var token = GetDynamicToken(); // get/genereate you dynamic token here.
var pactConfig = new PactVerifierConfig
{
Outputters = new List {
new XUnitOutputter(_output)
},
Verbose = true,
CustomHeader = new KeyValuePair<string, string>("Authorization", $"Bearer {token}")
};

        new PactVerifier(pactConfig)
            .ServiceProvider(providerName: "Provider", serviceUri)
            .HonoursPactWith("Consumer")
            .PactUri("Path to your contract file")
            .Verify();
    }

@mmysliwiec
Copy link
Author

Yes, I know. The problem is our authentication token is based on the request URL and it's different for each interaction so we can't generate it once.

@neilcampbell
Copy link
Member

Another option is to inject some middleware in your provider when you start it for verification. See #214

@neilcampbell
Copy link
Member

To answer your original question, no we currently don't have any plans to implement that feature. We are happy to discuss and accept PR's though 😄

@adamrodger
Copy link
Contributor

Closed due to inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants