Files
icarus/include/manager/TokenManager.h
T
2019-11-03 13:03:32 -05:00

40 lines
962 B
C++

#ifndef TOKEN_MANAGER_H_
#define TOKEN_MANAGER_H_
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include <cpr/cpr.h>
#include <jwt-cpp/jwt.h>
#include <nlohmann/json.hpp>
#include "model/Models.h"
#include "type/Scopes.h"
namespace manager {
class TokenManager {
public:
TokenManager() = default;
model::Token retrieveToken(const model::BinaryPath&);
bool isTokenValid(std::string&, type::Scope);
bool testAuth(const model::BinaryPath&);
private:
cpr::Response sendRequest(std::string_view, nlohmann::json&);
nlohmann::json createTokenBody(const model::AuthCredentials&);
model::AuthCredentials parseAuthCredentials(const model::BinaryPath&);
std::vector<std::string> extractScopes(const jwt::decoded_jwt&&);
std::pair<bool, std::vector<std::string>> fetchAuthHeader(const std::string&);
bool tokenSupportsScope(const std::vector<std::string>&, const std::string&&);
};
}
#endif