blob: 0f6e66786f74704da87b9a18fc21b29152578dce [file] [log] [blame]
Ed Tanousf9273472017-02-28 16:05:13 -08001#pragma once
2
3#include <crow/http_request.h>
4#include <crow/http_response.h>
5
Ed Tanous99923322017-03-03 14:21:24 -08006namespace crow {
Ed Tanousb4d29f42017-03-24 16:39:25 -07007
Ed Tanous1ff48782017-04-18 12:45:08 -07008struct User {};
Ed Tanousb4d29f42017-03-24 16:39:25 -07009
Ed Tanous99923322017-03-03 14:21:24 -080010struct TokenAuthorizationMiddleware {
Ed Tanousb4d29f42017-03-24 16:39:25 -070011 // TODO(ed) auth_token shouldn't really be passed to the context
12 // it opens the possibility of exposure by and endpoint.
13 // instead we should only pass some kind of "user" struct
Ed Tanous99923322017-03-03 14:21:24 -080014 struct context {
Ed Tanousc4771fb2017-03-13 13:39:49 -070015 std::string auth_token;
Ed Tanous99923322017-03-03 14:21:24 -080016 };
Ed Tanousf9273472017-02-28 16:05:13 -080017
Ed Tanous8041f312017-04-03 09:47:01 -070018 TokenAuthorizationMiddleware();
Ed Tanousc4771fb2017-03-13 13:39:49 -070019
Ed Tanous99923322017-03-03 14:21:24 -080020 void before_handle(crow::request& req, response& res, context& ctx);
Ed Tanousf9273472017-02-28 16:05:13 -080021
Ed Tanous99923322017-03-03 14:21:24 -080022 void after_handle(request& req, response& res, context& ctx);
Ed Tanous8041f312017-04-03 09:47:01 -070023
Ed Tanous1ff48782017-04-18 12:45:08 -070024 private:
25 std::string auth_token2;
Ed Tanous99923322017-03-03 14:21:24 -080026};
Ed Tanousf9273472017-02-28 16:05:13 -080027}