Skip to content

Webserver

Aleksandr Kirienko requested to merge webserver into develop

Created by: ZzDmitry

Архитектура практически как в предыдущих проектах, в частности, в cart smart lock.

Сейчас из АПИ - только авторизация через телеграм. Адмиты - только по налицию валидного токена, без привилегий.

Логин (ЖЖЖЖЖЖЖ - секретная информация, информацию для запроса можно получить запустив playground/telegram_auth_site/frontend/index.html и послав запрос - в девтулзе будет ответ от телеграма):

➜  ~ curl http://localhost:8001/login/ -X POST -d '{"id":220309383,"first_name":"Dmitry","username":"Dm1tr3","photo_url":"https:\/\/t.me\/i\/userpic\/320\/Dm1tr3.jpg","auth_date":1554868166,"hash":"ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ"}' -H "Content-Type: application/json" -i
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 165
ETag: W/"a5-teXGndn1grRv10MExMTKmiwNJRg"
Date: Wed, 10 Apr 2019 04:55:31 GMT
Connection: keep-alive

{"token":"ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ"}

Обновление токена:

➜  ~ curl http://localhost:8001/login/ -X PUT -H "authorization: Bearer ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ" -i
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 165
ETag: W/"a5-ZdDHLbtF4PjDunjIX6HnmjpB2OU"
Date: Wed, 10 Apr 2019 04:58:39 GMT
Connection: keep-alive

{"token":"ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ"}%

Без токена этот вызов запрещён:

➜  ~ curl http://localhost:8001/login/ -X PUT -i                                                                                                                                                           
HTTP/1.1 403 Forbidden
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 21
ETag: W/"15-TLNzmZqKxaTuFdX/dVWWPBu44/c"
Date: Wed, 10 Apr 2019 04:59:25 GMT
Connection: keep-alive

{"error":"Forbidden"}%  

С неверным токеном - неавторизрованы:

➜  ~ curl http://localhost:8001/login/ -X PUT -H "authorization: Bearer qqqqqqqqqqqqqqqqqqq" -i                                                                                                            
HTTP/1.1 401 Unauthorized
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 44
ETag: W/"2c-XI8XXWavVWGixarc5SrKRqJ4qz8"
Date: Wed, 10 Apr 2019 04:59:56 GMT
Connection: keep-alive

{"error":"JsonWebTokenError: jwt malformed"}%  

Merge request reports

Loading