19 lines
687 B
C
19 lines
687 B
C
#include "jwt.h"
|
|
#include "user.h"
|
|
#include "utils.h"
|
|
|
|
void verify_token(struct mg_connection *c, struct mg_http_message *hm) {
|
|
const request_with_token *data = check_body(hm);
|
|
if (data->error != nullptr) {
|
|
mg_http_reply(c, 403, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("error"), MG_ESC(data->error));
|
|
return;
|
|
}
|
|
const bool valid = jwt_verifyJWT(data->token, JWT_DEFAULT_SECRET);
|
|
if (!valid) {
|
|
mg_http_reply(c, 403, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("error"),
|
|
MG_ESC("invalid token"));
|
|
return;
|
|
}
|
|
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("valid"), MG_ESC("true"));
|
|
}
|