nextcloud / user_external

👥 External user authentication methods like IMAP, SMB and FTP
https://apps.nextcloud.com/apps/user_external
108 stars 64 forks source link

basic authentication now follows redirects! #54

Closed nerdmaennchen closed 5 years ago

nerdmaennchen commented 5 years ago

this should fix https://github.com/nextcloud/user_external/issues/45

all the best, Lutz

violoncelloCH commented 5 years ago

ahh, get_headers() should follow redirects by default?

nerdmaennchen commented 5 years ago

heyhey,

sorry for my late reply. I was surprised as well when I found out that get_headers already does follow redirects. regarding the use of max(): By all means I am no expert on php (all php code I've ever touched is the code you're dealing with just now). Anyways, after playing with the function for a bit more I figured there are two problems:

It only works if the headers in the response do not have numbers as keys (which they should not have anyways... I consider this a minor issue) Also, it only works in no-redirect situations if the HTTP-response field containing the error code is the first element.

I'm actually fairly sure that get_headers will always behave in a way that the element with index 0 will be the first of the returned array but the way my code utilizes this assumption is a bit of a stretch. I'm going to overhaul this part.

Thanks for pointing out the issues that come with max()!

Greetings from Guatemala, a lovely place with lovely people!

nerdmaennchen commented 5 years ago

I think using a regex for response checking would be a bit overkill. However, I think looking for the numerically greatest element of all elements with integer keys should do the trick.

My reasoning is that the return array from get_headers contains the header fields as a mapping (string -> string) as well as the response codes (int -> string). Only using array keys of type integer should suffice to actually solve both potential problems I've mentioned above.

All the best, Lutz