CommaApi: use auth.py for request authentication when on PC (#20755)
* CommaApi: use auth.py for request authentication when on PC * whitespace * only when replay * nicer way to do this * tabs * use bool * tabs * tabs * prefer this to just be state * initialize with stdString * tabs * include order * fix order + ifdef fix * whitespace'pull/20758/head
parent
1083d14f40
commit
a337097b5e
|
@ -72,7 +72,7 @@ QString CommaApi::create_jwt(QVector<QPair<QString, QJsonValue>> payloads, int e
|
|||
}
|
||||
|
||||
|
||||
HttpRequest::HttpRequest(QObject *parent, QString requestURL, const QString &cache_key) : cache_key(cache_key), QObject(parent) {
|
||||
HttpRequest::HttpRequest(QObject *parent, QString requestURL, const QString &cache_key, bool create_jwt_) : cache_key(cache_key), create_jwt(create_jwt_), QObject(parent) {
|
||||
networkAccessManager = new QNetworkAccessManager(this);
|
||||
reply = NULL;
|
||||
|
||||
|
@ -91,7 +91,15 @@ HttpRequest::HttpRequest(QObject *parent, QString requestURL, const QString &cac
|
|||
}
|
||||
|
||||
void HttpRequest::sendRequest(QString requestURL){
|
||||
QString token = CommaApi::create_jwt();
|
||||
QString token;
|
||||
if(create_jwt) {
|
||||
token = CommaApi::create_jwt();
|
||||
} else {
|
||||
QString token_json = QString::fromStdString(util::read_file(util::getenv_default("HOME", "/.comma/auth.json", "/.comma/auth.json")));
|
||||
QJsonDocument json_d = QJsonDocument::fromJson(token_json.toUtf8());
|
||||
token = json_d["access_token"].toString();
|
||||
}
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setUrl(QUrl(requestURL));
|
||||
request.setRawHeader(QByteArray("Authorization"), ("JWT " + token).toUtf8());
|
||||
|
|
|
@ -19,7 +19,7 @@ class CommaApi : public QObject {
|
|||
|
||||
public:
|
||||
static QByteArray rsa_sign(QByteArray data);
|
||||
static QString create_jwt(QVector<QPair<QString, QJsonValue>> payloads = {}, int expiry=3600);
|
||||
static QString create_jwt(QVector<QPair<QString, QJsonValue>> payloads = {}, int expiry = 3600);
|
||||
|
||||
private:
|
||||
QNetworkAccessManager* networkAccessManager;
|
||||
|
@ -33,7 +33,7 @@ class HttpRequest : public QObject {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit HttpRequest(QObject* parent, QString requestURL, const QString &cache_key = "");
|
||||
explicit HttpRequest(QObject* parent, QString requestURL, const QString &cache_key = "", bool create_jwt_ = true);
|
||||
QNetworkReply *reply;
|
||||
void sendRequest(QString requestURL);
|
||||
|
||||
|
@ -41,6 +41,7 @@ private:
|
|||
QNetworkAccessManager *networkAccessManager;
|
||||
QTimer *networkTimer;
|
||||
QString cache_key;
|
||||
bool create_jwt;
|
||||
|
||||
private slots:
|
||||
void requestTimeout();
|
||||
|
|
|
@ -3,8 +3,13 @@
|
|||
Replay::Replay(QString route_, int seek) : route(route_) {
|
||||
unlogger = new Unlogger(&events, &events_lock, &frs, seek);
|
||||
current_segment = 0;
|
||||
bool create_jwt = true;
|
||||
|
||||
http = new HttpRequest(this, "https://api.commadotai.com/v1/route/" + route + "/files");
|
||||
#if !defined(QCOM) && !defined(QCOM2)
|
||||
create_jwt = false;
|
||||
#endif
|
||||
|
||||
http = new HttpRequest(this, "https://api.commadotai.com/v1/route/" + route + "/files", "", create_jwt);
|
||||
QObject::connect(http, SIGNAL(receivedResponse(QString)), this, SLOT(parseResponse(QString)));
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include "FrameReader.hpp"
|
||||
#include "visionipc_server.h"
|
||||
|
||||
#include "common/util.h"
|
||||
|
||||
class Replay : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
|
|
Loading…
Reference in New Issue