ITV / scala-pact

A Scala implementation of CDC using the Pact standard
Other
108 stars 54 forks source link

scala-pact does not support HTTP Basic auth? #110

Closed jnatten closed 5 years ago

jnatten commented 5 years ago

I've tried to set it up in my pact.sbt like this: pactBrokerAddress := "http://username:password@pact-broker.local"

and whenever i run sbt pactPublish everything seems to go okay until the last second (when the actual publishing happens):

SimpleResponse(401,Map(Server -> nginx/1.14.0 + Phusion Passenger 5.3.6, Connection -> keep-alive, Content-Length -> 0, WWW-Authenticate -> Basic realm="Restricted area", Content-Type -> text/plain, Date -> Mon, 19 Nov 2018 09:32:28 GMT, X-Powered-By -> Phusion Passenger 5.3.6, Status -> 401 Unauthorized),Some())
Failed: 401, Some()

If i replace the header here: https://github.com/ITV/scala-pact/blob/602aeb08d76468503d109ab9ad56d636c2d8105d/sbt-scalapact-shared/src/main/scala/com/itv/scalapact/plugin/shared/Publisher.scala#L39

With this (dXNlcm5hbWU6cGFzc3dvcmQ= is "username:password" base64 encoded):

Map("Content-Type" -> "application/json", "Authorization" -> "Basic dXNlcm5hbWU6cGFzc3dvcmQ="),

The publish works and everything is fine.

Would you like me to create a pull-request adding basic auth header to requests to a broker?

jnatten commented 5 years ago

This could be implemented by adding the authorization header when creating the SimpleRequest (By parsing the url with a simple regex). Another option could be to parse the url in the implementations of IScalaPactHttpClient.

What do you think @davesmith00000 ?