slim-basic-auth icon indicating copy to clipboard operation
slim-basic-auth copied to clipboard

Fix Authorization header

Open willoucom opened this issue 5 years ago • 4 comments

Fixes #89

Since getHeaderLine() can return a coma separated string, i add an explode and a foreach.

Updated tests to reflect the change

willoucom avatar May 11 '20 14:05 willoucom

I agree to this solution. In my setup I provide a slim API for a frontend Vue application were I wanted to use basic auth to secure the API endpoint and a bearer token for user authentication. So my header looked like this:

Authorization: Basic <base64UserPasswd>, Bearer <jsonWebToken>

The approach from @willoucom made that work!

omega3000 avatar Mar 28 '22 13:03 omega3000

AFAIK header which looks like below is invalid syntax.

Authorization: Basic <base64UserPasswd>, Bearer <jsonWebToken>

tuupola avatar Mar 28 '22 14:03 tuupola

We occured the same issue in another scenario. It seems that the combination of AWS ALB, EKS ingress, an apache pod and HTTP/2 leads to a duplication of the header somewhere down the road, resulting in a Header like: Authorization: Basic foo,Basic foo

I agree that this is basically not the problem of the library, but it would add some resilience if the lib would just take the first header starting with "Basic".

nerdlibfront avatar May 12 '22 11:05 nerdlibfront

I agree with @tuupola , having 2 different authorization is invalid. There are multiple discussions on the Internet about this header and it seems that nobody agrees on a solution.

However, I think the problem with some loadbalancers (e.g. amazon/scaleway/azure) duplicating the header can lead to a lot of problems for developers wanting to use this library (which I consider great). To solve this problem, I can modify my patch to retrieve only the first element of the header and ignore the others, I think this will solve the problem caused by LBs and prevent misuse of the header (i.e. using multiple schemas in the same header).

What do you think about this alternative?

willoucom avatar May 12 '22 11:05 willoucom