summaryrefslogtreecommitdiff
path: root/src/token_authorization_middleware.cpp
diff options
context:
space:
mode:
authorEd Tanous <ed.tanous@intel.com>2017-03-04 01:21:24 +0300
committerEd Tanous <ed.tanous@intel.com>2017-03-04 01:21:24 +0300
commit9992332be956c173199257b55e592ec2d2331e3a (patch)
tree9b7b17d8c92f7ad2bf32404ff719961a5150d0af /src/token_authorization_middleware.cpp
parent38bdb986b9133f5d728cc44b3d82321ce132eee3 (diff)
downloadbmcweb-9992332be956c173199257b55e592ec2d2331e3a.tar.xz
clang-format
Diffstat (limited to 'src/token_authorization_middleware.cpp')
-rw-r--r--src/token_authorization_middleware.cpp79
1 files changed, 34 insertions, 45 deletions
diff --git a/src/token_authorization_middleware.cpp b/src/token_authorization_middleware.cpp
index d1972fadf1..aeef58c6a9 100644
--- a/src/token_authorization_middleware.cpp
+++ b/src/token_authorization_middleware.cpp
@@ -4,49 +4,38 @@
#include <token_authorization_middleware.hpp>
-namespace crow
-{
- std::string TokenAuthorizationMiddleware::context::get_cookie(const std::string& key)
- {
- if (cookie_sessions.count(key))
- return cookie_sessions[key];
- return {};
- }
-
- void TokenAuthorizationMiddleware::context::set_cookie(const std::string& key, const std::string& value)
- {
- cookies_to_push_to_client.emplace(key, value);
- }
-
-
- void TokenAuthorizationMiddleware::before_handle(crow::request& req, response& res, context& ctx)
- {
- auto return_unauthorized = [&req, &res](){
- res.code = 401;
- res.end();
- };
- if (req.url == "/login"){
-
- }
- // Check for an authorization header, reject if not present
- if (req.headers.count("Authorization") != 1) {
- return_unauthorized();
- return;
- }
-
- std::string auth_header = req.get_header_value("Authorization");
- // If the user is attempting any kind of auth other than token, reject
- if (!boost::starts_with(auth_header, "Token ")) {
- return_unauthorized();
- return;
- }
- }
-
- void TokenAuthorizationMiddleware::after_handle(request& /*req*/, response& res, context& ctx)
- {
- for (auto& cookie : ctx.cookies_to_push_to_client) {
- res.add_header("Set-Cookie", cookie.first + "=" + cookie.second);
- }
- }
-
+namespace crow {
+std::string TokenAuthorizationMiddleware::context::get_cookie(const std::string& key) {
+ if (cookie_sessions.count(key)) return cookie_sessions[key];
+ return {};
+}
+
+void TokenAuthorizationMiddleware::context::set_cookie(const std::string& key, const std::string& value) { cookies_to_push_to_client.emplace(key, value); }
+
+void TokenAuthorizationMiddleware::before_handle(crow::request& req, response& res, context& ctx) {
+ auto return_unauthorized = [&req, &res]() {
+ res.code = 401;
+ res.end();
+ };
+ if (req.url == "/login") {
+ }
+ // Check for an authorization header, reject if not present
+ if (req.headers.count("Authorization") != 1) {
+ return_unauthorized();
+ return;
+ }
+
+ std::string auth_header = req.get_header_value("Authorization");
+ // If the user is attempting any kind of auth other than token, reject
+ if (!boost::starts_with(auth_header, "Token ")) {
+ return_unauthorized();
+ return;
+ }
+}
+
+void TokenAuthorizationMiddleware::after_handle(request& /*req*/, response& res, context& ctx) {
+ for (auto& cookie : ctx.cookies_to_push_to_client) {
+ res.add_header("Set-Cookie", cookie.first + "=" + cookie.second);
+ }
+}
} \ No newline at end of file