From e04f75e1bfd2ed49665a46c8ddd5e72b99b56536 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Sat, 27 Oct 2018 15:45:21 +0800 Subject: [PATCH] web_backend: added GetExternalJWT function To support requesting external JWTs to use them as verification tokens. --- src/web_service/web_backend.cpp | 8 +++++++- src/web_service/web_backend.h | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index 84d6105d7..689be8c9c 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "common/common_types.h" #include "common/logging/log.h" @@ -134,7 +135,8 @@ struct Client::Impl { } if (content_type->second.find("application/json") == std::string::npos && - content_type->second.find("text/html; charset=utf-8") == std::string::npos) { + content_type->second.find("text/html; charset=utf-8") == std::string::npos && + content_type->second.find("text/plain; charset=utf-8") == std::string::npos) { LOG_ERROR(WebService, "{} to {} returned wrong content: {}", method, host + path, content_type->second); return Common::WebResult{Common::WebResult::Code::WrongContent, "Wrong content"}; @@ -193,4 +195,8 @@ Common::WebResult Client::DeleteJson(const std::string& path, const std::string& return impl->GenericJson("DELETE", path, data, allow_anonymous); } +Common::WebResult Client::GetExternalJWT(const std::string& audience) { + return PostJson(fmt::format("/jwt/external/{}", audience), "", false); +} + } // namespace WebService diff --git a/src/web_service/web_backend.h b/src/web_service/web_backend.h index c637e09df..d366d642c 100644 --- a/src/web_service/web_backend.h +++ b/src/web_service/web_backend.h @@ -46,6 +46,13 @@ public: Common::WebResult DeleteJson(const std::string& path, const std::string& data, bool allow_anonymous); + /** + * Requests an external JWT for the specific audience provided. + * @param audience the audience of the JWT requested. + * @return the result of the request. + */ + Common::WebResult GetExternalJWT(const std::string& audience); + private: struct Impl; std::unique_ptr impl;