diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2020-06-20 14:09:21 -0400 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2020-07-01 07:33:57 +0200 |
commit | fa96934861b075cffd980cdfa98f61dee82fc012 (patch) | |
tree | 32bf713b29a5b7eafd09df69cccb39399be28165 /common/Authorization.cpp | |
parent | wsd: support --cleanup in loolwsd (diff) | |
download | online-fa96934861b075cffd980cdfa98f61dee82fc012.tar.gz online-fa96934861b075cffd980cdfa98f61dee82fc012.zip |
wsd: Authorization parsing and creation improvements
Authorization class now handles the parsing and creation
of its instances, which makes it centralized.
We also avoid repeatedly constructing Authorization objects
in ClientSession and instead do it once at construction
and cache it.
A bunch of new unit-tests added.
Change-Id: I9b5939be51a5957214d07ed8f1096efd179686c6
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96825
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'common/Authorization.cpp')
-rw-r--r-- | common/Authorization.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/common/Authorization.cpp b/common/Authorization.cpp index ad4381ef55..93c5704fc2 100644 --- a/common/Authorization.cpp +++ b/common/Authorization.cpp @@ -88,4 +88,26 @@ void Authorization::authorizeRequest(Poco::Net::HTTPRequest& request) const } } +Authorization Authorization::create(const Poco::URI::QueryParameters& queryParams) +{ + // prefer the access_token + std::string decoded; + for (const auto& param : queryParams) + { + if (param.first == "access_token") + { + Poco::URI::decode(param.second, decoded); + return Authorization(Authorization::Type::Token, decoded); + } + + if (param.first == "access_header") + Poco::URI::decode(param.second, decoded); + } + + if (!decoded.empty()) + return Authorization(Authorization::Type::Header, decoded); + + return Authorization(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |