Hi there! I’m trying to use feature stubs (<https:...
# pact-broker
r
Hi there! I’m trying to use feature stubs (https://docs.pactflow.io/docs/stubs/#finding-the-url-to-a-pact-resource) But when I send request to https://test.pactflow.io/pacts/provider/pactflow-example-provider/consumer/pactflow-example-consumer/latest/stub/user/1 (not exactly this one but similar) I’m getting an error
{*"*errors*"*=>[{*"*message*"*=>*"*401 Unauthorized. Please see <https://docs.pactflow.io/docs/login-help> for more information.*\n"*}]}>
The question is which Auth field in headers do I need to specify? How to combine it using my token?
m
FYI just note this is a #CLS16AVEE question (hosted stubs are not on the open source Pact Broker)
I believe the authorization you need to provide is the PactFlow bearer token
(hence the error message there)
oh, in that case, it’s the basic auth user/password (if you’re using test.pactflow.io)
r
thanks I'll try
👍 1
m
Out of interest, what’s your use case?
r
So we have bunch of VCR cassettes (https://github.com/vcr/vcr) which we're trying to substitute with Pact stubs
m
ha, interesting!
Authorization is a tricky one, we currently don’t support it well on stubs (because the auth to PactFlow trumps it). It should be straightforward enough to support, either by: 1. Removing auth for stubs (not ideal, but perhaps it could be made configurable) 2. Allowing a separate auth header to PactFlow for the use case (it does mean your API client would need to add it though) 3. Or some other means Thoughts?
r
ok. Before you mentioned that I need to add header: "Authorization: Basic xxxx" xxxx- as I understand it's an encoded base64 combination of
email:password
?
m
This header should do it
Copy code
Authorization: Basic ZFhmbHR5Rk1nTk9GWkF4cjhpbzl3SjM3aVVwWTQyTTpPNUFJWld4ZWxXYkx2cU1kOFBrQVZ5Y0JKaDJQc3lnMQ==
It’s the basic auth credentials you would have needed to get to test.pactflow.io
(they are safe to share, they’re in many places on the internet for that test account)
r
nice but I have my own broker and own stub url 'https://teladochealth.pactflow.io/pacts/provider/tas/consumer/health-info/latest/stub/' I tried base64 of email:password but still getting 401
m
oh right, in that case, it should be your API token
✅ 1
head to
/settings/api-tokens
on your broker
r
still not working I tried different combinations
Copy code
Authorization: Basic token
Authorization: Basic base64(token)
Authorization: Basic base64(email:token)
Authorization: Basic base64(email:password)
m
right sorry, it would be
Bearer <token>
(no need to encode your API token)
I was confused earlier by the other broker, which whilst hosted on PactFlow, is a little hybrid PactFlow/Pact Broker (as can be seen by the old UI!)
the PactFlow accounts are behind Bearer tokens
r
Oh. Still getting 401
*"*Authorization*"*=>*"*Bearer my-secret-token*"*
m
is the error body the same or different?
It’s possible you’ve gotten through PactFlow’s auth, but are getting a
401
from the stub (probably not, but possible)
r
error body is the same
{*"*errors*"*=>[{*"*message*"*=>*"*401 Unauthorized. Please see <https://docs.pactflow.io/docs/login-help> for more information.*\n"*}]}
m
Mind DM’ing me please and we can get you sorted?
✅ 1
actually, before you do that - try this:
Copy code
curl -H"Authorization: Bearer <token>" <https://teladochealth.pactflow.io/> -v
Obviosuly, replace your token