Waziup / WaziGate

Waziup LoRa Edge gateway
21 stars 20 forks source link

API: Authorization bearer not working #154

Closed cdupont closed 3 years ago

cdupont commented 3 years ago

Using Authorization bearer is not working. However, Cookie header is working.

$ curl -X GET "http://wazigate.local/devices" -H  "accept: application/json" -H "Authorization: Bearer=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJjbGllbnQiOiI2MDE3Yzc0Zjc4NDUyNDAwMDYwMzYwYTgiLCJleHAiOjE2MTg4NDg0NTF9.TnlSoNOYNTs9E1T9soB3CXuc9ZI-w4OwLZE0hdGO3rc"
Unauthorized
mojtaba-esk commented 3 years ago

I checked the code and if you call it this way, it will work:

$ curl -X GET "http://wazigate.local/devices" -H  "accept: application/json" -H "Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJjbGllbnQiOiI2MDE3Yzc0Zjc4NDUyNDAwMDYwMzYwYTgiLCJleHAiOjE2MTg4NDg0NTF9.TnlSoNOYNTs9E1T9soB3CXuc9ZI-w4OwLZE0hdGO3rc"

A complete example:

TOKEN=`curl -X POST "http://wazigate.local/auth/token" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"username\":\"admin\",\"password\":\"loragateway\"}" | tr -d '"'`

curl -X GET "http://wazigate.local/devices" -H  "accept: application/json" -H "Token: $TOKEN"
cdupont commented 3 years ago

Thanks. The HTTP standard seems to use "Authorization: Bearer XXX": https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization

mojtaba-esk commented 3 years ago

Yes I guessed so, I will improve it to make it standard

mojtaba-esk commented 3 years ago

Fixed

cdupont commented 3 years ago

This is tested here: https://github.com/Waziup/WaziGate/blob/master/tests/tests.py#L61 and working:)

teegwende commented 1 year ago

$ curl -X GET "http://wazigate.local/devices" -H "accept: application/json" -H "Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJjbGllbnQiOiI2MDE3Yzc0Zjc4NDUyNDAwMDYwMzYwYTgiLCJleHAiOjE2MTg4NDg0NTF9.TnlSoNOYNTs9E1T9soB3CXuc9ZI-w4OwLZE0hdGO3rc"

Hello guys, I am facing the same problem of unauthorized error. I tried your solution, but I still have the same issue. Can you please help me ?