mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-19 19:29:58 +00:00
web_backend: protect jwt cache with a mutex
This commit is contained in:
parent
120d8f3bf7
commit
62f9409ba3
2 changed files with 4 additions and 1 deletions
|
@ -24,6 +24,7 @@ Client::JWTCache Client::jwt_cache{};
|
||||||
|
|
||||||
Client::Client(const std::string& host, const std::string& username, const std::string& token)
|
Client::Client(const std::string& host, const std::string& username, const std::string& token)
|
||||||
: host(host), username(username), token(token) {
|
: host(host), username(username), token(token) {
|
||||||
|
std::lock_guard<std::mutex> lock(jwt_cache.mutex);
|
||||||
if (username == jwt_cache.username && token == jwt_cache.token) {
|
if (username == jwt_cache.username && token == jwt_cache.token) {
|
||||||
jwt = jwt_cache.jwt;
|
jwt = jwt_cache.jwt;
|
||||||
}
|
}
|
||||||
|
@ -116,6 +117,7 @@ void Client::UpdateJWT() {
|
||||||
if (result.result_code != Common::WebResult::Code::Success) {
|
if (result.result_code != Common::WebResult::Code::Success) {
|
||||||
LOG_ERROR(WebService, "UpdateJWT failed");
|
LOG_ERROR(WebService, "UpdateJWT failed");
|
||||||
} else {
|
} else {
|
||||||
|
std::lock_guard<std::mutex> lock(jwt_cache.mutex);
|
||||||
jwt_cache.username = username;
|
jwt_cache.username = username;
|
||||||
jwt_cache.token = token;
|
jwt_cache.token = token;
|
||||||
jwt_cache.jwt = jwt = result.returned_data;
|
jwt_cache.jwt = jwt = result.returned_data;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <future>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <httplib.h>
|
#include <httplib.h>
|
||||||
|
@ -81,6 +81,7 @@ private:
|
||||||
std::unique_ptr<httplib::Client> cli;
|
std::unique_ptr<httplib::Client> cli;
|
||||||
|
|
||||||
struct JWTCache {
|
struct JWTCache {
|
||||||
|
std::mutex mutex;
|
||||||
std::string username;
|
std::string username;
|
||||||
std::string token;
|
std::string token;
|
||||||
std::string jwt;
|
std::string jwt;
|
||||||
|
|
Loading…
Reference in a new issue