aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/Net/src/OAuth20Credentials.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/libs/poco/Net/src/OAuth20Credentials.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/libs/poco/Net/src/OAuth20Credentials.cpp')
-rw-r--r--contrib/libs/poco/Net/src/OAuth20Credentials.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/contrib/libs/poco/Net/src/OAuth20Credentials.cpp b/contrib/libs/poco/Net/src/OAuth20Credentials.cpp
new file mode 100644
index 0000000000..392115ad5f
--- /dev/null
+++ b/contrib/libs/poco/Net/src/OAuth20Credentials.cpp
@@ -0,0 +1,105 @@
+//
+// OAuth20Credentials.cpp
+//
+// Library: Net
+// Package: OAuth
+// Module: OAuth20Credentials
+//
+// Copyright (c) 2014, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// SPDX-License-Identifier: BSL-1.0
+//
+
+
+#include "Poco/Net/OAuth20Credentials.h"
+#include "Poco/Net/HTTPRequest.h"
+#include "Poco/Net/NetException.h"
+#include "Poco/String.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+const std::string OAuth20Credentials::SCHEME = "Bearer";
+
+
+OAuth20Credentials::OAuth20Credentials():
+ _scheme(SCHEME)
+{
+}
+
+
+OAuth20Credentials::OAuth20Credentials(const std::string& bearerToken):
+ _bearerToken(bearerToken),
+ _scheme(SCHEME)
+{
+}
+
+
+OAuth20Credentials::OAuth20Credentials(const std::string& bearerToken, const std::string& scheme):
+ _bearerToken(bearerToken),
+ _scheme(scheme)
+{
+}
+
+
+OAuth20Credentials::OAuth20Credentials(const HTTPRequest& request):
+ _scheme(SCHEME)
+{
+ extractBearerToken(request);
+}
+
+
+OAuth20Credentials::OAuth20Credentials(const HTTPRequest& request, const std::string& scheme):
+ _scheme(scheme)
+{
+ extractBearerToken(request);
+}
+
+
+OAuth20Credentials::~OAuth20Credentials()
+{
+}
+
+
+void OAuth20Credentials::setBearerToken(const std::string& bearerToken)
+{
+ _bearerToken = bearerToken;
+}
+
+
+void OAuth20Credentials::setScheme(const std::string& scheme)
+{
+ _scheme = scheme;
+}
+
+
+void OAuth20Credentials::authenticate(HTTPRequest& request)
+{
+ std::string auth(_scheme);
+ auth += ' ';
+ auth += _bearerToken;
+ request.set(HTTPRequest::AUTHORIZATION, auth);
+}
+
+
+void OAuth20Credentials::extractBearerToken(const HTTPRequest& request)
+{
+ if (request.hasCredentials())
+ {
+ std::string authScheme;
+ std::string authInfo;
+ request.getCredentials(authScheme, authInfo);
+ if (icompare(authScheme, _scheme) == 0)
+ {
+ _bearerToken = authInfo;
+ }
+ else throw NotAuthenticatedException("No bearer token in Authorization header", authScheme);
+ }
+ else throw NotAuthenticatedException("No Authorization header found");
+}
+
+
+} } // namespace Poco::Net