alecritson/Placid-Statamic

Support for Basic Auth in v2?

sxdj opened this issue · 5 comments

sxdj commented

Hi, the plugins seems very promising! Tested it with public API and works like charm.

However, I'd like to pull data from the Helpscout Docs API which requires HTTP Basic Authentication: username and a (dummy) password.

I tried #1 as it seemed pretty similar, but it's not working for me (partly because I don't understand the formatting in the example, like why the comma?) but maybe that only worked for v1 and not v2?

This is my placid.yaml:

helpscout:
    url: 'https://docsapi.helpscout.net/v1/collections/HERE_OUR_ID/articles'
    curl:
      auth: [HERE_OUR_API_TOKEN,X]

And my template:

{{ placid:request handle="helpscout" }}
    {{ if no_results }}
        No results
    {{ else }}
        Squirrels!
    {{ endif }}
{{ /placid:request }}

Keep getting "No results". Also tried with {{ response }} and see if data was returned, but no luck so far. Any suggestions? Thanks for your Addon!

Hi @sxdj

Looks like you're referencing options that were part of v1, can you try something like:

helpscout:
    url: 'https://docsapi.helpscout.net/v1/collections/HERE_OUR_ID/articles'
    headers:
      auth: [HERE_OUR_API_TOKEN,X]

And see if that works, I can't test this as I don't have an upgraded Helpscout account.

sxdj commented

Hi @alecritson your suggestion doesn't work (yet) but I can play with it a bit. It would help a lot if I can dump the whole response so that I can verify if the auth credentials are accepted or not. Is there a way to get that response?

Sure if you dive into here: https://github.com/alecritson/Placid-Statamic/blob/v2/Placid/PlacidTags.php#L87 and remove the try/catch it should just put the error out.

I'm currently putting together the next version, this will be a complete rewrite and will give tons more info when things aren't working as expected!

sxdj commented

Got it working now! By showing the error, I found that the basic authentication was a problem as it didn't accept the required (dummy) password which isn't allowed to be empty for the Helpscout API. The solution was to generate an authentication header to combine username + password into one hash.

With the following values in placid.yaml it's working:

helpscout:
    url: 'https://docsapi.helpscout.net/v1/collections/HERE_OUR_ID/articles'
    headers:
      Authorization: Basic HERE_THE_HASHED_HEADER_CODE

Thanks for your help and great to hear that you're working on a new version!

Sweet, glad it's working for you! Will close this issue if it's resolved. Otherwise feel free to re open.