[squeak-dev] https & woocommerce; basicAuth etc?

Levente Uzonyi leves at caesar.elte.hu
Mon Oct 1 21:30:48 UTC 2018


On Mon, 1 Oct 2018, tim Rowledge wrote:

>
>
>> On 2018-10-01, at 1:01 PM, Chris Cunningham <cunningham.cb at gmail.com> wrote:
>> 
>> Are you using WebClient?  It is actually documented int he help system, check it out, especially the Authentication section. It does basic and digest authentication, apparently.
>
> Sigh. I looked at the help, having noticed that webclient/server was one of the too few facilities with decent help some time ago. And I looked *right past* the bit I needed.
>
> Nurse! Bring me some new dried frog pills!
>
> More germanely, the webclient seems to want to do a request without any authorisation stuff, get back a '401' and retry with some authorisation - but from quickly debugging, WebClient>>#authenticate:from: is expecting a 'WWW-Authenticate' header section that simply isn't there. That would get used to choose the auth method. I haven't seen anything that makes me think I can force the woocommerce stuff to provide that header data. No idea if it is really a good scheme to rely upon it.
>
> I suspect I can make up a way to do a more direct use-auth-first-time approach that might be better when you know it has to have it. After my frog pills...

Yes you can. You just have to add the Authorization header yourself. 
Adding basic auth manually to the example in help would look something 
like this:

 	| client username password response |
 	client := WebClient new.
 	username := 'Tim'.
 	password := 'secret'.
 	response := client httpGet: 'http://www.squeak.org/protected' do: [ :request |
 		request headerAt: 'Authorization' put: 'Basic ', (username, ':', password) base64Encoded ].
 	response content. "Prefetch response body before closing the client."
 	client close. "Do not let WebClient instances leak external semaphores."
 	^response

Levente

>
>
> tim
> --
> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
> Strange OpCodes: SFA: Seek Financial Assistance


More information about the Squeak-dev mailing list